# -*- coding: cp1254 -*-
# for M&B v.901

from header_common import *
from header_operations import *
from module_constants import *
from header_parties import *
from header_skills import *
from header_mission_templates import *
from header_items import *
from header_triggers import *
from header_terrain_types import *
from header_colors import *

####################################################################################################################
# scripts is a list of script records.
# Each script record contns the following two fields:
# 1) Script id: The prefix "script_" will be inserted when referencing scripts.
# 2) Operation block: This must be a valid operation block. See header_operations.py for reference.
####################################################################################################################

scripts = [
('game_start',
  #game_start:
  # This script is called when a new game is started
  # INPUT: none("game_start",
		[
			# party name
			(str_store_troop_name, s5, "trp_player"),
			(str_store_string,s5,"@{s5}'s Party"),
			(party_set_name, "p_main_party", s5),
			#player icon
			(party_set_slot,'p_main_party',slot_party_icon,'icon_player'),
			(party_set_slot,'p_main_party',slot_party_icon_state,pis_normal),
			# debug stuff
			(assign,'$g_test_party_no',hyogo),
			# food morale bonus
			(try_for_range,':item','itm_rice','itm_hemp'),
				(item_set_slot,':item',slot_item_food_bonus,2),
			(try_end),
			(item_set_slot,'itm_sake',slot_item_food_bonus,5),
			(item_set_slot,'itm_kyoto_sake',slot_item_food_bonus,7),
			(item_set_slot,'itm_rice',slot_item_food_bonus,3),
			(item_set_slot,'itm_dried_meat',slot_item_food_bonus,4),
			(item_set_slot,'itm_dried_beef',slot_item_food_bonus,4),
			(item_set_slot,'itm_smoked_fish',slot_item_food_bonus,4),
			(item_set_slot,'itm_salted_fish',slot_item_food_bonus,3),
			(item_set_slot,'itm_sushi_fish',slot_item_food_bonus,4),
			(item_set_slot,'itm_millet',slot_item_food_bonus,1),
			#storyline quest arrays
			# bushi
		    (call_script,'script_array_initialize',8),
			(assign,'$bushi_storyline_quest_array','$return'),
			(try_for_range,':storyline_quest','qst_storyline_bushi_establish_outpost','qst_bushi_suppress_rebels'),
				(call_script,'script_array_push','$bushi_storyline_quest_array',':storyline_quest'),
			(try_end),
			(quest_set_slot,'qst_storyline_bushi_enemy_patrols',slot_quest_shugo_dialog,'str_qst_storyline_bushi_enemy_patrols'),
			(quest_set_slot,'qst_storyline_bushi_establish_outpost',slot_quest_shugo_dialog,'str_qst_storyline_bushi_establish_outpost'),
			(quest_set_slot,'qst_storyline_bushi_rebellion',slot_quest_shugo_dialog,'str_qst_storyline_bushi_rebellion'),
			(quest_set_slot,'qst_storyline_bushi_war',slot_quest_shugo_dialog,'str_qst_storyline_bushi_war'),
			(quest_set_slot,'qst_storyline_bushi_establish_outpost_2',slot_quest_shugo_dialog,'str_qst_storyline_bushi_establish_outpost_2'),
			(quest_set_slot,'qst_storyline_bushi_rebellion_2',slot_quest_shugo_dialog,'str_qst_storyline_bushi_rebellion_2'),
			(quest_set_slot,'qst_storyline_bushi_enemy_army',slot_quest_shugo_dialog,'str_qst_storyline_bushi_enemy_army'),
			(quest_set_slot,'qst_storyline_bushi_war_2',slot_quest_shugo_dialog,'str_qst_storyline_bushi_war_2'),
			# ronin
			(call_script,'script_array_initialize',8),
			(assign,'$ronin_storyline_quest_array','$return'),
			(try_for_range,':storyline_quest','qst_ronin_storyline_capture_bandit_leader','qst_ronin_defeat_bandit_parties'),
				(call_script,'script_array_push','$ronin_storyline_quest_array',':storyline_quest'),
			(try_end),
			# kuge - currently dummies
			(call_script,'script_array_initialize',8),
			(assign,'$kuge_storyline_quest_array','$return'),
			(try_for_range,':storyline_quest',0,8),
				(call_script,'script_array_push','$kuge_storyline_quest_array',':storyline_quest'),
			(try_end),
			# merchant - missing one
			(call_script,'script_array_initialize',8),
			(assign,'$merchant_storyline_quest_array','$return'),
			(try_for_range,':storyline_quest','qst_merchant_storyline_establish_trading_post','qst_merchant_storyline_secure_supplier'),
				(call_script,'script_array_push','$merchant_storyline_quest_array',':storyline_quest'),
			(try_end),
			# set initial factions
		    (try_for_range,':town',all_towns_begin,all_towns_end),
		        (store_faction_of_party,':faction',':town'),
		        (party_set_slot,':town',slot_town_initial_faction,':faction'),
		    (try_end),    
			(call_script,'script_array_initialize',12),
			(assign,':template_composition_array','$return'),
			# troop id, min, max
			(call_script,'script_array_push',':template_composition_array','trp_veteran_defender'),
			(call_script,'script_array_push',':template_composition_array',0),
			(call_script,'script_array_push',':template_composition_array',7),
			(call_script,'script_array_push',':template_composition_array','trp_village_defender'),
			(call_script,'script_array_push',':template_composition_array',5),
			(call_script,'script_array_push',':template_composition_array',12),
			(call_script,'script_array_push',':template_composition_array','trp_villager'),
			(call_script,'script_array_push',':template_composition_array',7),
			(call_script,'script_array_push',':template_composition_array',18),
			(call_script,'script_array_push',':template_composition_array','trp_farmer'),
			(call_script,'script_array_push',':template_composition_array',8),
			(call_script,'script_array_push',':template_composition_array',20),
			(party_template_set_slot,'pt_local_patrol',slot_template_village_garrison_composition,':template_composition_array'),
			###### town garrison
			(call_script,'script_array_initialize',9),
			(assign,':template_composition_array','$return'),
			(call_script,'script_array_push',':template_composition_array','trp_t2_light_cav_n'),
			(call_script,'script_array_push',':template_composition_array',1),
			(call_script,'script_array_push',':template_composition_array',8),
			(call_script,'script_array_push',':template_composition_array','trp_t2_spear_samurai_n'),
			(call_script,'script_array_push',':template_composition_array',5),
			(call_script,'script_array_push',':template_composition_array',15),
			(call_script,'script_array_push',':template_composition_array','trp_t2_spear_ashigaru_n'),
			(call_script,'script_array_push',':template_composition_array',10),
			(call_script,'script_array_push',':template_composition_array',25),
			(party_template_set_slot,'pt_local_patrol',slot_template_town_garrison_composition,':template_composition_array'),
			###### city garrison
			(call_script,'script_array_initialize',12),
			(assign,':template_composition_array','$return'),
			(call_script,'script_array_push',':template_composition_array','trp_t3_heavy_cav_n'),
			(call_script,'script_array_push',':template_composition_array',0),
			(call_script,'script_array_push',':template_composition_array',7),
			(call_script,'script_array_push',':template_composition_array','trp_t3_light_cav_n'),
			(call_script,'script_array_push',':template_composition_array',5),
			(call_script,'script_array_push',':template_composition_array',12),
			(call_script,'script_array_push',':template_composition_array','trp_t2_spear_samurai_n'),
			(call_script,'script_array_push',':template_composition_array',7),
			(call_script,'script_array_push',':template_composition_array',18),
			(call_script,'script_array_push',':template_composition_array','trp_t2_spear_ashigaru_n'),
			(call_script,'script_array_push',':template_composition_array',8),
			(call_script,'script_array_push',':template_composition_array',20),
			(party_template_set_slot,'pt_local_patrol',slot_template_city_garrison_composition,':template_composition_array'),
			###### cost arrays
			(call_script,'script_init_village_garrison'),
			(call_script,'script_init_town_garrison'),
			(call_script,'script_init_city_garrison'),
			###### initial troop level
			(call_script,'script_init_garrison_troop_levels'),
			###### set up template spawn costs
			(party_template_set_slot,'pt_army',slot_template_spawn_cost,100000),
			(party_template_set_slot,'pt_hosokawa_kuge',slot_template_spawn_cost,10000),
			(party_template_set_slot,'pt_yamana_kuge',slot_template_spawn_cost,10000),
			(party_template_set_slot,'pt_hosokawa_war_party',slot_template_spawn_cost,35000),
			(party_template_set_slot,'pt_hosokawa_raiders',slot_template_spawn_cost,20000),
			(party_template_set_slot,'pt_hosokawa_patrol',slot_template_spawn_cost,16000),
			(party_template_set_slot,'pt_yamana_war_party',slot_template_spawn_cost,35000),
			(party_template_set_slot,'pt_yamana_raiders',slot_template_spawn_cost,20000),
			(party_template_set_slot,'pt_yamana_patrol',slot_template_spawn_cost,16000),
			(party_template_set_slot,'pt_spy',slot_template_spawn_cost,100),
			(party_template_set_slot,'pt_builder',slot_template_spawn_cost,1000),
			(party_template_set_slot,'pt_village_patrol',slot_template_spawn_cost,1000),
			(party_template_set_slot,'pt_town_patrol',slot_template_spawn_cost,5000),
			(party_template_set_slot,'pt_city_patrol',slot_template_spawn_cost,25000),
			(party_template_set_slot,'pt_city_reinforcements_a',slot_template_spawn_cost,3500),
			(party_template_set_slot,'pt_city_reinforcements_b',slot_template_spawn_cost,2000),
			(party_template_set_slot,'pt_city_reinforcements_c',slot_template_spawn_cost,500),
			(party_template_set_slot,'pt_town_reinforcements_a',slot_template_spawn_cost,2000),
			(party_template_set_slot,'pt_town_reinforcements_b',slot_template_spawn_cost,1000),
			(party_template_set_slot,'pt_town_reinforcements_c',slot_template_spawn_cost,300),
			(party_template_set_slot,'pt_village_reinforcements_a',slot_template_spawn_cost,500),
			(party_template_set_slot,'pt_village_reinforcements_b',slot_template_spawn_cost,250),
			(party_template_set_slot,'pt_village_reinforcements_c',slot_template_spawn_cost,100),
			(party_template_set_slot,'pt_hosokawa_reinforcements_a',slot_template_spawn_cost,40000),
			(party_template_set_slot,'pt_hosokawa_reinforcements_b',slot_template_spawn_cost,10000),
			(party_template_set_slot,'pt_hosokawa_reinforcements_c',slot_template_spawn_cost,5000),
			(party_template_set_slot,'pt_hosokawa_reinforcements_d',slot_template_spawn_cost,1000),
			(party_template_set_slot,'pt_yamana_reinforcements_a',slot_template_spawn_cost,40000),
			(party_template_set_slot,'pt_yamana_reinforcements_b',slot_template_spawn_cost,10000),
			(party_template_set_slot,'pt_yamana_reinforcements_c',slot_template_spawn_cost,5000),
			(party_template_set_slot,'pt_yamana_reinforcements_d',slot_template_spawn_cost,1000),
			############# initialize the troop costs
			(try_for_range,':troop_id','trp_ronin','trp_hosokawa_katsumoto'),
				(troop_get_inventory_capacity,':inv_cap',':troop_id'),
				(assign,':loop_break',false),
				(try_for_range,':i',0,':inv_cap'),
					(eq,':loop_break',false),
					(troop_get_inventory_slot,':item',':troop_id',':i'),
					(is_between,':item','itm_pack_horse','itm_waraji_a'),
					(assign,':has_horse',1),
					(assign,':loop_break',true), # should break out of loop
				(try_end),
				(store_character_level, ":wage", ":troop_id"),
		        (val_add, ":wage", 5),
				(val_mul,':wage',':wage'),
				(val_mul,':wage',10),
				(val_div, ":wage", 312),
				(try_begin),
					(eq,':has_horse',1),
					(val_mul,':wage',5),
				(try_end),
				(troop_set_slot,':troop_id',slot_troop_cost,':wage'),
			(try_end),
			(try_for_range,reg1,'fac_neutral','fac_end_fac'),
				(set_relation,'fac_outlaws',reg1,-50),
			(try_end),
# Initialize faction allies
			(faction_set_slot,"fac_hosokawa",slot_faction_hosokawa_ally,1),
			(faction_set_slot,"fac_akamatsu",slot_faction_hosokawa_ally,1),
			(faction_set_slot,"fac_hosokawa_hatakeyama",slot_faction_hosokawa_ally,1),
			(faction_set_slot,"fac_takeda",slot_faction_hosokawa_ally,1),
			(faction_set_slot,"fac_kyogoku",slot_faction_hosokawa_ally,1), 
			(faction_set_slot,"fac_yamana",slot_faction_yamana_ally,1),
			(faction_set_slot,"fac_ishikki",slot_faction_yamana_ally,1),
			(faction_set_slot,"fac_yamana_hatakeyama",slot_faction_yamana_ally,1),
			(faction_set_slot,"fac_rokkaku",slot_faction_yamana_ally,1),
			(faction_set_slot,"fac_toki",slot_faction_yamana_ally,1),
			(faction_set_slot,"fac_shiba",slot_faction_yamana_ally,1),
# Initialize faction parameters
			(faction_set_slot,"fac_hosokawa",slot_faction_strength,500),
			(faction_set_slot,"fac_yamana",slot_faction_strength,500),
			(faction_set_slot,"fac_hosokawa",slot_faction_spawn_points,500000),
			(faction_set_slot,"fac_yamana",slot_faction_spawn_points,500000),
# faction leaders
			(faction_set_slot,'fac_player_faction',slot_faction_leader,'trp_player'),
			(faction_set_slot,'fac_hosokawa',slot_faction_leader,'trp_hosokawa_katsumoto'),
			(faction_set_slot,'fac_hosokawa_kuge',slot_faction_leader,'trp_hosokawa_katsumoto'),
			(faction_set_slot,'fac_akamatsu',slot_faction_leader,'trp_himeji_shugo'),
			(faction_set_slot,'fac_hosokawa_hatakeyama',slot_faction_leader,'trp_bushi_10'),
			(faction_set_slot,'fac_takeda',slot_faction_leader,'trp_obama_shugo'),
			(faction_set_slot,'fac_kyogoku',slot_faction_leader,'trp_otsu_shugo'),
			(faction_set_slot,'fac_yamana',slot_faction_leader,'trp_yamana_souzen'),
			(faction_set_slot,'fac_yamana_kuge',slot_faction_leader,'trp_yamana_souzen'),
			(faction_set_slot,'fac_ishikki',slot_faction_leader,'trp_miyazu_shugo'),
			(faction_set_slot,'fac_yamana_hatakeyama',slot_faction_leader,'trp_nara_shugo'),
			(faction_set_slot,'fac_rokkaku',slot_faction_leader,'trp_bushi_52'),
			(faction_set_slot,'fac_toki',slot_faction_leader,'trp_bushi_50'),
			(faction_set_slot,'fac_shiba',slot_faction_leader,'trp_tsuruga_shugo'),
			(faction_set_slot,'fac_enza',slot_faction_leader,'trp_city_12_merchant'),
			(faction_set_slot,'fac_ginza',slot_faction_leader,'trp_city_6_merchant'),
			(faction_set_slot,'fac_andaza',slot_faction_leader,'trp_city_9_merchant'),
			(try_for_range,':faction_no','fac_hosokawa','fac_end_fac'),
				(call_script,'script_update_faction_notes',':faction_no'),
				(faction_set_slot,':faction_no',slot_faction_morale,morale_neutral),
				(faction_set_slot,':faction_no',slot_faction_joined,false),
			(try_end),
			(try_for_range,':troop_no',bushi_begin,bushi_end),
				(call_script,'script_update_troop_notes',':troop_no'),
			(try_end),
			(try_for_range,':center_no',cities_begin,villages_end),
				(call_script,'script_update_center_notes',':center_no'),
			(try_end),
			(faction_set_slot,'fac_hosokawa',slot_faction_quest,'qst_faction_hosokawa'),
			(faction_set_slot,'fac_hosokawa',slot_faction_enemy_faction,'fac_yamana'),
			(faction_set_slot,'fac_hosokawa',slot_faction_letter,'itm_hosokawa_intro_letter'),
			(faction_set_slot,'fac_yamana',slot_faction_quest,'qst_faction_yamana'),
			(faction_set_slot,'fac_yamana',slot_faction_enemy_faction,'fac_hosokawa'),
			(faction_set_slot,'fac_yamana',slot_faction_letter,'itm_yamana_intro_letter'),
			(faction_set_slot,'fac_enza',slot_faction_quest,'qst_faction_enza'),
			(faction_set_slot,'fac_ginza',slot_faction_quest,'qst_faction_ginza'),
			(faction_set_slot,'fac_andaza',slot_faction_quest,'qst_faction_andaza'),
# initialize faction quest slots
			(quest_set_slot,'qst_faction_enza',slot_quest_za_faction_item,'itm_salt'),
			(quest_set_slot,'qst_faction_ginza',slot_quest_za_faction_item,'itm_silver_bars'),
			(quest_set_slot,'qst_faction_andaza',slot_quest_za_faction_item,'itm_oil'),
			(quest_set_slot,'qst_faction_enza',slot_quest_za_faction,'fac_enza'),
			(quest_set_slot,'qst_faction_ginza',slot_quest_za_faction,'fac_ginza'),
			(quest_set_slot,'qst_faction_andaza',slot_quest_za_faction,'fac_andaza'),
# initialize faction reinforcements
			(faction_set_slot,'fac_hosokawa',slot_faction_reinforcements_a,'pt_hosokawa_reinforcements_a'),
			(faction_set_slot,'fac_hosokawa',slot_faction_reinforcements_b,'pt_hosokawa_reinforcements_b'),
			(faction_set_slot,'fac_hosokawa',slot_faction_reinforcements_c,'pt_hosokawa_reinforcements_c'),
			(faction_set_slot,'fac_hosokawa',slot_faction_reinforcements_d,'pt_hosokawa_reinforcements_d'),
			(faction_set_slot,'fac_yamana',slot_faction_reinforcements_a,'pt_yamana_reinforcements_a'),
			(faction_set_slot,'fac_yamana',slot_faction_reinforcements_b,'pt_yamana_reinforcements_b'),
			(faction_set_slot,'fac_yamana',slot_faction_reinforcements_c,'pt_yamana_reinforcements_c'),
			(faction_set_slot,'fac_yamana',slot_faction_reinforcements_d,'pt_yamana_reinforcements_d'),
# initialize faction possession flags
			(try_for_range,':mode',1,5),
				(call_script,'script_faction_set_possession_flags','fac_hosokawa',':mode'),
			(try_end),
			(try_for_range,':mode',1,5),
				(call_script,'script_faction_set_possession_flags','fac_yamana',':mode'),
			(try_end),
# initialize quest time parameters
			(try_for_range,':quest_no',0,'qst_end_quests'),
				(quest_set_slot,':quest_no',slot_quest_timed,false),
			(try_end),
#Initalize Armies
			(try_begin),
				(call_script,'script_cf_faction_spawn_army','fac_hosokawa',90000,110000,false,sakai),
				(call_script,'script_cf_faction_spawn_army','fac_hosokawa',90000,110000,false,kameyama),
				(call_script,'script_cf_faction_spawn_army','fac_yamana',90000,110000,false,nara),
				(call_script,'script_cf_faction_spawn_army','fac_yamana',90000,110000,false,fukuchiyama),
			(try_end),
# Initialize possession flags
			(call_script,'script_check_city_status','fac_hosokawa'),
			(call_script,'script_check_city_status','fac_yamana'),
# initialize npc lords wealth
			(try_for_range,':ai_troop',npc_lords_begin,npc_lords_end),
				(store_random_in_range,reg10,80000,120000),
				(troop_add_gold,':ai_troop',reg10),
				(call_script,'script_modify_troop_wealth',':ai_troop'),
			(try_end),
# System globals
			(assign,'$g_menu_caller',0),
			(assign,'$cheat_mode',0),
			(assign,'$g_exit_menu',false),
# Misc global constants
			(assign,"$day",1),
			(assign,"$g_month",7),
			(assign,"$year",2127),
	        (assign,"$summer_harvest_active",0),
	        (assign,"$autumn_harvest_active",0),
	        (assign,"$spring_harvest_active",0),
	        # (assign,'$time',6),
	        # (assign,'$clock',0),
			(assign,'$g_bandits_spawn_flag',0),
			(assign,'$war_begin',0),
			(assign,'$g_max_faction_forts',3),
			(assign,'$g_num_team_members',0),
			(assign,'$g_player_besiege_town',0),
			(assign,'$visiting_kuge_conversation',0),
			(assign,'$return_to_shugo_scene',0),
			(assign,'$emissary_complete',-1),
			# (assign,'$shugo_quest_target',-1),
			# (assign,'$shugo_quest_giver',-1),
			(assign,'$joined_bandits',0),
			(assign,'$g_debug_msg_on',false),
			(assign,'$g_talk_troop',0),
			(assign,'$g_day_counter',1),
# Unavailable menu options
	        (assign,'$mno_unavailable',1),
	        (assign,'$companion_training_begin',0),
	        (assign,'$g_num_active_traveling_farmers',0),
			(assign,'$g_num_active_traveling_merchants',0),
# Max bandit parties
	        (assign,"$max_river_pirates",12),
	        (assign,"$max_bandits",20),
	        (assign,"$max_forest_bandits",12),
	        (assign,"$max_mountain_bandits",12),
	        (assign,"$max_sea_raiders",12),
	        (assign,"$max_bandit_raiders",20),
			(assign,"$max_bandit_lesser_hordes",5),
			(assign,"$max_bandit_hordes",5),
			(assign,'$g_bandit_spawn_script_loop_counter',0),
# Max police parties
	        (assign,"$max_local_patrols",50),
# Max Hosokawa parties
	        (assign,"$max_hosokawa_foragers",8),
	        (assign,"$max_hosokawa_patrols",8),
	        (assign,"$max_hosokawa_scouts",6),
	        (assign,"$max_hosokawa_raiders",6),
	        (assign,"$max_hosokawa_war_parties",4),
	        (assign,"$max_hosokawa_messengers",4),
	        (assign,"$max_hosokawa_armies",3),
	        (assign,"$max_hosokawa_supply_trains",6),
# Max Yamana parties
	        (assign,"$max_yamana_foragers",8),
	        (assign,"$max_yamana_patrols",8),
	        (assign,"$max_yamana_scouts",6),
	        (assign,"$max_yamana_raiders",6),
	        (assign,"$max_yamana_war_parties",4),
	        (assign,"$max_yamana_messengers",4),
	        (assign,"$max_yamana_armies",3),
	        (assign,"$max_yamana_supply_trains",6),
# Max mercs
	        (assign,"$max_city_ronin",12),
	        (assign,"$max_large_town_ronin",8),
	        (assign,"$max_town_ronin",6),
	        (assign,"$max_city_farmers",16),
	        (assign,"$max_large_town_farmers",14),
	        (assign,"$max_town_farmers",12),
	        (assign,"$max_large_village_farmers",10),
	        (assign,"$max_village_farmers",8),
# Class and rank parameters - lots of array packing to follow
			(call_script,'script_initialize_classes'),
			(try_begin),
				(check_quest_active,'qst_class_bushi'),
				(troop_set_slot,'trp_player',slot_player_rank_array,'$g_bushi_rank_array'),
			(else_try),
				(check_quest_active,'qst_class_kuge'),
				(troop_set_slot,'trp_player',slot_player_rank_array,'$g_kuge_rank_array'),
			# (else_try),
				# (check_quest_active,'qst_class_bushi'),
				# (troop_set_slot,'trp_player',slot_player_rank_array,'$g_bushi_rank_array'),
			# (else_try),
				# (check_quest_active,'qst_class_bushi'),
				# (troop_set_slot,'trp_player',slot_player_rank_array,'$g_bushi_rank_array'),
			(try_end),
			(assign,':town',south_kyoto),
			 (try_for_range,':merchant',"trp_city_1_merchant","trp_city_1_armorer"),
				 (troop_set_slot,':merchant',slot_troop_city,':town'),
				 (val_add,':town',1),
			 (try_end),
			 (assign,':town',hyogo),
			 (try_for_range,':kokujin',"trp_city_5_kokujin","trp_city_1_innkeeper"),
				 (troop_set_slot,':kokujin',slot_troop_city,':town'),
				 (val_add,':town',1),
			 (try_end),
#Initialize sensei
			 (troop_set_slot,"trp_mitsumaru",slot_sensei_prof_oh,0),
			 (troop_set_slot,"trp_mitsumaru",slot_sensei_prof_th,50),
			 (troop_set_slot,"trp_mitsumaru",slot_sensei_prof_pl,0),
			 (troop_set_slot,"trp_mitsumaru",slot_sensei_prof_ar,0),
			 (troop_set_slot,"trp_mitsumaru",slot_sensei_prof_tr,0),
			 (troop_set_slot,"trp_mitsumaru",slot_sensei_skl_ps,1),
			 (troop_set_slot,"trp_mitsumaru",slot_sensei_skl_pd,0),
			 (troop_set_slot,"trp_mitsumaru",slot_sensei_skl_pt,0),
			 (troop_set_slot,"trp_mitsumaru",slot_sensei_skl_wm,0),
			 (troop_set_slot,"trp_mitsumaru",slot_sensei_skl_ath,0),
			 (troop_set_slot,"trp_mitsumaru",slot_sensei_weapon_type,sword),
			 (troop_set_slot,"trp_mitsumaru",slot_sensei_apprentice,'trp_south_kyoto_dojo_apprentice'),
			 (troop_set_slot,"trp_mitsumaru",slot_sensei_flag,sf_mitsumaru),
			 (scene_set_slot,'scn_south_kyoto_dojo',slot_dojo_sensei,'trp_mitsumaru'),
			 (scene_set_slot,'scn_south_kyoto_dojo',slot_dojo_trainee,-1),
			 (scene_set_slot,'scn_south_kyoto_dojo',slot_dojo_training,0),
			 (scene_set_slot,'scn_south_kyoto_dojo',slot_dojo_sensei_away,0),

			 (troop_set_slot,"trp_tomomoto",slot_sensei_prof_oh,0),
			 (troop_set_slot,"trp_tomomoto",slot_sensei_prof_th,100),
			 (troop_set_slot,"trp_tomomoto",slot_sensei_prof_pl,0),
			 (troop_set_slot,"trp_tomomoto",slot_sensei_prof_ar,0),
			 (troop_set_slot,"trp_tomomoto",slot_sensei_prof_tr,0),
			 (troop_set_slot,"trp_tomomoto",slot_sensei_skl_ps,1),
			 (troop_set_slot,"trp_tomomoto",slot_sensei_skl_pd,0),
			 (troop_set_slot,"trp_tomomoto",slot_sensei_skl_pt,0),
			 (troop_set_slot,"trp_tomomoto",slot_sensei_skl_wm,1),
			 (troop_set_slot,"trp_tomomoto",slot_sensei_skl_ath,0),
			 (troop_set_slot,"trp_tomomoto",slot_sensei_weapon_type,sword),
			 (troop_set_slot,"trp_tomomoto",slot_sensei_apprentice,'trp_yodo_dojo_apprentice'),
			 (troop_set_slot,"trp_tomomoto",slot_sensei_flag,sf_tomomoto),
			 (scene_set_slot,'scn_yodo_dojo',slot_dojo_sensei,'trp_tomomoto'),
			 (scene_set_slot,'scn_yodo_dojo',slot_dojo_trainee,-1),
			 (scene_set_slot,'scn_yodo_dojo',slot_dojo_training,0),
			 (scene_set_slot,'scn_yodo_dojo',slot_dojo_sensei_away,0),

			 (troop_set_slot,"trp_teruhisa",slot_sensei_prof_oh,0),
			 (troop_set_slot,"trp_teruhisa",slot_sensei_prof_th,100),
			 (troop_set_slot,"trp_teruhisa",slot_sensei_prof_pl,0),
			 (troop_set_slot,"trp_teruhisa",slot_sensei_prof_ar,0),
			 (troop_set_slot,"trp_teruhisa",slot_sensei_prof_tr,0),
			 (troop_set_slot,"trp_teruhisa",slot_sensei_skl_ps,1),
			 (troop_set_slot,"trp_teruhisa",slot_sensei_skl_pd,0),
			 (troop_set_slot,"trp_teruhisa",slot_sensei_skl_pt,0),
			 (troop_set_slot,"trp_teruhisa",slot_sensei_skl_wm,0),
			 (troop_set_slot,"trp_teruhisa",slot_sensei_skl_ath,1),
			 (troop_set_slot,"trp_teruhisa",slot_sensei_weapon_type,sword),
			 (troop_set_slot,"trp_teruhisa",slot_sensei_apprentice,'trp_hikone_dojo_apprentice'),
			 (troop_set_slot,"trp_teruhisa",slot_sensei_flag,sf_teruhisa),
			 (scene_set_slot,'scn_hikone_dojo',slot_dojo_sensei,'trp_teruhisa'),
			 (scene_set_slot,'scn_hikone_dojo',slot_dojo_trainee,-1),
			 (scene_set_slot,'scn_hikone_dojo',slot_dojo_training,0),
			 (scene_set_slot,'scn_hikone_dojo',slot_dojo_sensei_away,0),

			 (troop_set_slot,"trp_kiyouji",slot_sensei_prof_oh,0),
			 (troop_set_slot,"trp_kiyouji",slot_sensei_prof_th,0),
			 (troop_set_slot,"trp_kiyouji",slot_sensei_prof_pl,100),
			 (troop_set_slot,"trp_kiyouji",slot_sensei_prof_ar,0),
			 (troop_set_slot,"trp_kiyouji",slot_sensei_prof_tr,0),
			 (troop_set_slot,"trp_kiyouji",slot_sensei_skl_ps,1),
			 (troop_set_slot,"trp_kiyouji",slot_sensei_skl_pd,0),
			 (troop_set_slot,"trp_kiyouji",slot_sensei_skl_pt,0),
			 (troop_set_slot,"trp_kiyouji",slot_sensei_skl_wm,0),
			 (troop_set_slot,"trp_kiyouji",slot_sensei_skl_ath,0),
			 (troop_set_slot,"trp_kiyouji",slot_sensei_weapon_type,bladed_polearm),
			 (troop_set_slot,"trp_kiyouji",slot_sensei_apprentice,'trp_haga_dojo_apprentice'),
			 (troop_set_slot,"trp_kiyouji",slot_sensei_flag,sf_kiyouji),
			 (scene_set_slot,'scn_haga_dojo',slot_dojo_sensei,'trp_kiyouji'),
			 (scene_set_slot,'scn_haga_dojo',slot_dojo_trainee,-1),
			 (scene_set_slot,'scn_haga_dojo',slot_dojo_training,0),
			 (scene_set_slot,'scn_haga_dojo',slot_dojo_sensei_away,0),

			 (troop_set_slot,"trp_ietsuru",slot_sensei_prof_oh,0),
			 (troop_set_slot,"trp_ietsuru",slot_sensei_prof_th,0),
			 (troop_set_slot,"trp_ietsuru",slot_sensei_prof_pl,0),
			 (troop_set_slot,"trp_ietsuru",slot_sensei_prof_ar,100),
			 (troop_set_slot,"trp_ietsuru",slot_sensei_prof_tr,0),
			 (troop_set_slot,"trp_ietsuru",slot_sensei_skl_ps,0),
			 (troop_set_slot,"trp_ietsuru",slot_sensei_skl_pd,1),
			 (troop_set_slot,"trp_ietsuru",slot_sensei_skl_pt,0),
			 (troop_set_slot,"trp_ietsuru",slot_sensei_skl_wm,1),
			 (troop_set_slot,"trp_ietsuru",slot_sensei_skl_ath,1),
			 (troop_set_slot,"trp_ietsuru",slot_sensei_weapon_type,archery),
			 (troop_set_slot,"trp_ietsuru",slot_sensei_apprentice,'trp_imazu_dojo_apprentice'),
			 (troop_set_slot,"trp_ietsuru",slot_sensei_flag,sf_ietsuru),
			 (scene_set_slot,'scn_imazu_dojo',slot_dojo_sensei,'trp_ietsuru'),
			 (scene_set_slot,'scn_imazu_dojo',slot_dojo_trainee,-1),
			 (scene_set_slot,'scn_imazu_dojo',slot_dojo_training,0),
			 (scene_set_slot,'scn_imazu_dojo',slot_dojo_sensei_away,0),

			 (troop_set_slot,"trp_tsunetomo",slot_sensei_prof_oh,0),
			 (troop_set_slot,"trp_tsunetomo",slot_sensei_prof_th,0),
			 (troop_set_slot,"trp_tsunetomo",slot_sensei_prof_pl,0),
			 (troop_set_slot,"trp_tsunetomo",slot_sensei_prof_ar,150),
			 (troop_set_slot,"trp_tsunetomo",slot_sensei_prof_tr,0),
			 (troop_set_slot,"trp_tsunetomo",slot_sensei_skl_ps,0),
			 (troop_set_slot,"trp_tsunetomo",slot_sensei_skl_pd,1),
			 (troop_set_slot,"trp_tsunetomo",slot_sensei_skl_pt,0),
			 (troop_set_slot,"trp_tsunetomo",slot_sensei_skl_wm,1),
			 (troop_set_slot,"trp_tsunetomo",slot_sensei_skl_ath,0),
			 (troop_set_slot,"trp_tsunetomo",slot_sensei_weapon_type,archery),
			 (troop_set_slot,"trp_tsunetomo",slot_sensei_apprentice,'trp_oya_dojo_apprentice'),
			 (troop_set_slot,"trp_tsunetomo",slot_sensei_flag,sf_tsunetomo),
			 (scene_set_slot,'scn_oya_dojo',slot_dojo_sensei,'trp_tsunetomo'),
			 (scene_set_slot,'scn_oya_dojo',slot_dojo_trainee,-1),
			 (scene_set_slot,'scn_oya_dojo',slot_dojo_training,0),
			 (scene_set_slot,'scn_oya_dojo',slot_dojo_sensei_away,0),

			 (troop_set_slot,"trp_ujiaru",slot_sensei_prof_oh,0),
			 (troop_set_slot,"trp_ujiaru",slot_sensei_prof_th,0),
			 (troop_set_slot,"trp_ujiaru",slot_sensei_prof_pl,100),
			 (troop_set_slot,"trp_ujiaru",slot_sensei_prof_ar,0),
			 (troop_set_slot,"trp_ujiaru",slot_sensei_prof_tr,0),
			 (troop_set_slot,"trp_ujiaru",slot_sensei_skl_ps,1),
			 (troop_set_slot,"trp_ujiaru",slot_sensei_skl_pd,0),
			 (troop_set_slot,"trp_ujiaru",slot_sensei_skl_pt,0),
			 (troop_set_slot,"trp_ujiaru",slot_sensei_skl_wm,0),
			 (troop_set_slot,"trp_ujiaru",slot_sensei_skl_ath,1),
			 (troop_set_slot,"trp_ujiaru",slot_sensei_weapon_type,blunt_polearm),
			 (troop_set_slot,"trp_ujiaru",slot_sensei_apprentice,'trp_oe_dojo_apprentice'),
			 (troop_set_slot,"trp_ujiaru",slot_sensei_flag,sf_ujiaru),
			 (scene_set_slot,'scn_oe_dojo',slot_dojo_sensei,'trp_ujiaru'),
			 (scene_set_slot,'scn_oe_dojo',slot_dojo_trainee,-1),
			 (scene_set_slot,'scn_oe_dojo',slot_dojo_training,0),
			 (scene_set_slot,'scn_oe_dojo',slot_dojo_sensei_away,0),

			 (troop_set_slot,"trp_michimori",slot_sensei_prof_oh,50),
			 (troop_set_slot,"trp_michimori",slot_sensei_prof_th,0),
			 (troop_set_slot,"trp_michimori",slot_sensei_prof_pl,0),
			 (troop_set_slot,"trp_michimori",slot_sensei_prof_ar,0),
			 (troop_set_slot,"trp_michimori",slot_sensei_prof_tr,100),
			 (troop_set_slot,"trp_michimori",slot_sensei_skl_ps,0),
			 (troop_set_slot,"trp_michimori",slot_sensei_skl_pd,0),
			 (troop_set_slot,"trp_michimori",slot_sensei_skl_pt,1),
			 (troop_set_slot,"trp_michimori",slot_sensei_skl_wm,0),
			 (troop_set_slot,"trp_michimori",slot_sensei_skl_ath,1),
			 (troop_set_slot,"trp_michimori",slot_sensei_weapon_type,thrown),
			 (troop_set_slot,"trp_michimori",slot_sensei_apprentice,'trp_iga_dojo_apprentice'),
			 (troop_set_slot,"trp_michimori",slot_sensei_flag,sf_michimori),
			 (scene_set_slot,'scn_iga_dojo',slot_dojo_sensei,'trp_michimori'),
			 (scene_set_slot,'scn_iga_dojo',slot_dojo_trainee,-1),
			 (scene_set_slot,'scn_iga_dojo',slot_dojo_training,0),
			 (scene_set_slot,'scn_iga_dojo',slot_dojo_sensei_away,0),
#Initialize shugo
			(troop_set_slot,"trp_takase_shugo",slot_troop_city,takase),
			(troop_set_slot,"trp_sakai_shugo",slot_troop_city,sakai),
			(troop_set_slot,"trp_himeji_shugo",slot_troop_city,himeji),
			(troop_set_slot,"trp_kameyama_shugo",slot_troop_city,kameyama),
			(troop_set_slot,"trp_otsu_shugo",slot_troop_city,otsu),
			(troop_set_slot,"trp_obama_shugo",slot_troop_city,obama),
			(troop_set_slot,"trp_hidaka_shugo",slot_troop_city,hidaka),
			(troop_set_slot,"trp_miyazu_shugo",slot_troop_city,miyazu),
			(troop_set_slot,"trp_tsuruga_shugo",slot_troop_city,tsuruga),
			(troop_set_slot,"trp_nara_shugo",slot_troop_city,nara),
			(troop_set_slot,"trp_fujidera_shugo",slot_troop_city,fujidera),
			(troop_set_slot,"trp_ueno_shugo",slot_troop_city,ueno),
			(troop_set_slot,"trp_wakayama_shugo",slot_troop_city,wakayama),
# Initialize items
			(item_set_slot,'itm_art_scrolls',slot_item_seaside,0),
			(item_set_slot,'itm_art_scrolls',slot_item_island,0),
			(item_set_slot,'itm_art_scrolls',slot_item_lakeside,0),
			(item_set_slot,'itm_art_scrolls',slot_item_lowland,0),
			(item_set_slot,'itm_art_scrolls',slot_item_highland,0),
			(item_set_slot,'itm_art_scrolls',slot_item_low_valley,0),
			(item_set_slot,'itm_art_scrolls',slot_item_high_valley,0),
			(item_set_slot,'itm_art_scrolls',slot_item_small_village,0),
			(item_set_slot,'itm_art_scrolls',slot_item_village,0),
			(item_set_slot,'itm_art_scrolls',slot_item_large_village,0),
			(item_set_slot,'itm_art_scrolls',slot_item_town,0),
			(item_set_slot,'itm_art_scrolls',slot_item_large_town,100),
			(item_set_slot,'itm_art_scrolls',slot_item_city,200),
			(item_set_slot,'itm_art_scrolls',slot_item_port,0),
			(item_set_slot,'itm_art_scrolls',slot_item_jan,100),
			(item_set_slot,'itm_art_scrolls',slot_item_feb,100),
			(item_set_slot,'itm_art_scrolls',slot_item_mar,100),
			(item_set_slot,'itm_art_scrolls',slot_item_apr,100),
			(item_set_slot,'itm_art_scrolls',slot_item_may,100),
			(item_set_slot,'itm_art_scrolls',slot_item_jun,100),
			(item_set_slot,'itm_art_scrolls',slot_item_jul,100),
			(item_set_slot,'itm_art_scrolls',slot_item_aug,100),
			(item_set_slot,'itm_art_scrolls',slot_item_sep,100),
			(item_set_slot,'itm_art_scrolls',slot_item_oct,100),
			(item_set_slot,'itm_art_scrolls',slot_item_nov,100),
			(item_set_slot,'itm_art_scrolls',slot_item_dec,100),
			(item_set_slot,'itm_art_scrolls',slot_item_demand_coefficient,0),

			(item_set_slot,'itm_azuki_beans',slot_item_seaside,100),
			(item_set_slot,'itm_azuki_beans',slot_item_island,0),
			(item_set_slot,'itm_azuki_beans',slot_item_lakeside,100),
			(item_set_slot,'itm_azuki_beans',slot_item_lowland,300),
			(item_set_slot,'itm_azuki_beans',slot_item_highland,0),
			(item_set_slot,'itm_azuki_beans',slot_item_low_valley,0),
			(item_set_slot,'itm_azuki_beans',slot_item_high_valley,0),
			(item_set_slot,'itm_azuki_beans',slot_item_small_village,0),
			(item_set_slot,'itm_azuki_beans',slot_item_village,0),
			(item_set_slot,'itm_azuki_beans',slot_item_large_village,100),
			(item_set_slot,'itm_azuki_beans',slot_item_town,100),
			(item_set_slot,'itm_azuki_beans',slot_item_large_town,0),
			(item_set_slot,'itm_azuki_beans',slot_item_city,0),
			(item_set_slot,'itm_azuki_beans',slot_item_port,0),
			(item_set_slot,'itm_azuki_beans',slot_item_jan,20),
			(item_set_slot,'itm_azuki_beans',slot_item_feb,0),
			(item_set_slot,'itm_azuki_beans',slot_item_mar,0),
			(item_set_slot,'itm_azuki_beans',slot_item_apr,0),
			(item_set_slot,'itm_azuki_beans',slot_item_may,0),
			(item_set_slot,'itm_azuki_beans',slot_item_jun,0),
			(item_set_slot,'itm_azuki_beans',slot_item_jul,0),
			(item_set_slot,'itm_azuki_beans',slot_item_aug,0),
			(item_set_slot,'itm_azuki_beans',slot_item_sep,100),
			(item_set_slot,'itm_azuki_beans',slot_item_oct,80),
			(item_set_slot,'itm_azuki_beans',slot_item_nov,50),
			(item_set_slot,'itm_azuki_beans',slot_item_dec,30),
			(item_set_slot,'itm_azuki_beans',slot_item_demand_coefficient,0),

			(item_set_slot,'itm_bamboo_goods',slot_item_seaside,100),
			(item_set_slot,'itm_bamboo_goods',slot_item_island,0),
			(item_set_slot,'itm_bamboo_goods',slot_item_lakeside,200),
			(item_set_slot,'itm_bamboo_goods',slot_item_lowland,200),
			(item_set_slot,'itm_bamboo_goods',slot_item_highland,300),
			(item_set_slot,'itm_bamboo_goods',slot_item_low_valley,200),
			(item_set_slot,'itm_bamboo_goods',slot_item_high_valley,200),
			(item_set_slot,'itm_bamboo_goods',slot_item_small_village,0),
			(item_set_slot,'itm_bamboo_goods',slot_item_village,0),
			(item_set_slot,'itm_bamboo_goods',slot_item_large_village,100),
			(item_set_slot,'itm_bamboo_goods',slot_item_town,0),
			(item_set_slot,'itm_bamboo_goods',slot_item_large_town,0),
			(item_set_slot,'itm_bamboo_goods',slot_item_city,0),
			(item_set_slot,'itm_bamboo_goods',slot_item_port,0),
			(item_set_slot,'itm_bamboo_goods',slot_item_jan,75),
			(item_set_slot,'itm_bamboo_goods',slot_item_feb,50),
			(item_set_slot,'itm_bamboo_goods',slot_item_mar,25),
			(item_set_slot,'itm_bamboo_goods',slot_item_apr,0),
			(item_set_slot,'itm_bamboo_goods',slot_item_may,0),
			(item_set_slot,'itm_bamboo_goods',slot_item_jun,0),
			(item_set_slot,'itm_bamboo_goods',slot_item_jul,0),
			(item_set_slot,'itm_bamboo_goods',slot_item_aug,0),
			(item_set_slot,'itm_bamboo_goods',slot_item_sep,0),
			(item_set_slot,'itm_bamboo_goods',slot_item_oct,0),
			(item_set_slot,'itm_bamboo_goods',slot_item_nov,50),
			(item_set_slot,'itm_bamboo_goods',slot_item_dec,100),
			(item_set_slot,'itm_bamboo_goods',slot_item_demand_coefficient,500),

			(item_set_slot,'itm_books',slot_item_seaside,0),
			(item_set_slot,'itm_books',slot_item_island,0),
			(item_set_slot,'itm_books',slot_item_lakeside,0),
			(item_set_slot,'itm_books',slot_item_lowland,0),
			(item_set_slot,'itm_books',slot_item_highland,0),
			(item_set_slot,'itm_books',slot_item_low_valley,0),
			(item_set_slot,'itm_books',slot_item_high_valley,0),
			(item_set_slot,'itm_books',slot_item_small_village,0),
			(item_set_slot,'itm_books',slot_item_village,0),
			(item_set_slot,'itm_books',slot_item_large_village,0),
			(item_set_slot,'itm_books',slot_item_town,100),
			(item_set_slot,'itm_books',slot_item_large_town,200),
			(item_set_slot,'itm_books',slot_item_city,300),
			(item_set_slot,'itm_books',slot_item_port,0),
			(item_set_slot,'itm_books',slot_item_jan,100),
			(item_set_slot,'itm_books',slot_item_feb,100),
			(item_set_slot,'itm_books',slot_item_mar,100),
			(item_set_slot,'itm_books',slot_item_apr,100),
			(item_set_slot,'itm_books',slot_item_may,100),
			(item_set_slot,'itm_books',slot_item_jun,100),
			(item_set_slot,'itm_books',slot_item_jul,100),
			(item_set_slot,'itm_books',slot_item_aug,100),
			(item_set_slot,'itm_books',slot_item_sep,100),
			(item_set_slot,'itm_books',slot_item_oct,100),
			(item_set_slot,'itm_books',slot_item_nov,100),
			(item_set_slot,'itm_books',slot_item_dec,100),
			(item_set_slot,'itm_books',slot_item_demand_coefficient,0),

			(item_set_slot,'itm_calligraphy_scrolls',slot_item_seaside,0),
			(item_set_slot,'itm_calligraphy_scrolls',slot_item_island,0),
			(item_set_slot,'itm_calligraphy_scrolls',slot_item_lakeside,0),
			(item_set_slot,'itm_calligraphy_scrolls',slot_item_lowland,0),
			(item_set_slot,'itm_calligraphy_scrolls',slot_item_highland,0),
			(item_set_slot,'itm_calligraphy_scrolls',slot_item_low_valley,0),
			(item_set_slot,'itm_calligraphy_scrolls',slot_item_high_valley,0),
			(item_set_slot,'itm_calligraphy_scrolls',slot_item_small_village,0),
			(item_set_slot,'itm_calligraphy_scrolls',slot_item_village,0),
			(item_set_slot,'itm_calligraphy_scrolls',slot_item_large_village,0),
			(item_set_slot,'itm_calligraphy_scrolls',slot_item_town,100),
			(item_set_slot,'itm_calligraphy_scrolls',slot_item_large_town,100),
			(item_set_slot,'itm_calligraphy_scrolls',slot_item_city,200),
			(item_set_slot,'itm_calligraphy_scrolls',slot_item_port,0),
			(item_set_slot,'itm_calligraphy_scrolls',slot_item_jan,0),
			(item_set_slot,'itm_calligraphy_scrolls',slot_item_feb,0),
			(item_set_slot,'itm_calligraphy_scrolls',slot_item_mar,0),
			(item_set_slot,'itm_calligraphy_scrolls',slot_item_apr,0),
			(item_set_slot,'itm_calligraphy_scrolls',slot_item_may,0),
			(item_set_slot,'itm_calligraphy_scrolls',slot_item_jun,0),
			(item_set_slot,'itm_calligraphy_scrolls',slot_item_jul,0),
			(item_set_slot,'itm_calligraphy_scrolls',slot_item_aug,0),
			(item_set_slot,'itm_calligraphy_scrolls',slot_item_sep,0),
			(item_set_slot,'itm_calligraphy_scrolls',slot_item_oct,0),
			(item_set_slot,'itm_calligraphy_scrolls',slot_item_nov,0),
			(item_set_slot,'itm_calligraphy_scrolls',slot_item_dec,0),
			(item_set_slot,'itm_calligraphy_scrolls',slot_item_demand_coefficient,0),

			(item_set_slot,'itm_charcoal',slot_item_seaside,0),
			(item_set_slot,'itm_charcoal',slot_item_island,0),
			(item_set_slot,'itm_charcoal',slot_item_lakeside,0),
			(item_set_slot,'itm_charcoal',slot_item_lowland,0),
			(item_set_slot,'itm_charcoal',slot_item_highland,700),
			(item_set_slot,'itm_charcoal',slot_item_low_valley,500),
			(item_set_slot,'itm_charcoal',slot_item_high_valley,400),
			(item_set_slot,'itm_charcoal',slot_item_small_village,0),
			(item_set_slot,'itm_charcoal',slot_item_village,100),
			(item_set_slot,'itm_charcoal',slot_item_large_village,200),
			(item_set_slot,'itm_charcoal',slot_item_town,0),
			(item_set_slot,'itm_charcoal',slot_item_large_town,0),
			(item_set_slot,'itm_charcoal',slot_item_city,0),
			(item_set_slot,'itm_charcoal',slot_item_port,0),
			(item_set_slot,'itm_charcoal',slot_item_jan,30),
			(item_set_slot,'itm_charcoal',slot_item_feb,20),
			(item_set_slot,'itm_charcoal',slot_item_mar,20),
			(item_set_slot,'itm_charcoal',slot_item_apr,20),
			(item_set_slot,'itm_charcoal',slot_item_may,20),
			(item_set_slot,'itm_charcoal',slot_item_jun,20),
			(item_set_slot,'itm_charcoal',slot_item_jul,20),
			(item_set_slot,'itm_charcoal',slot_item_aug,20),
			(item_set_slot,'itm_charcoal',slot_item_sep,100),
			(item_set_slot,'itm_charcoal',slot_item_oct,100),
			(item_set_slot,'itm_charcoal',slot_item_nov,80),
			(item_set_slot,'itm_charcoal',slot_item_dec,60),
			(item_set_slot,'itm_charcoal',slot_item_demand_coefficient,0),

			(item_set_slot,'itm_chinese_silk',slot_item_seaside,0),
			(item_set_slot,'itm_chinese_silk',slot_item_island,0),
			(item_set_slot,'itm_chinese_silk',slot_item_lakeside,0),
			(item_set_slot,'itm_chinese_silk',slot_item_lowland,0),
			(item_set_slot,'itm_chinese_silk',slot_item_highland,0),
			(item_set_slot,'itm_chinese_silk',slot_item_low_valley,0),
			(item_set_slot,'itm_chinese_silk',slot_item_high_valley,0),
			(item_set_slot,'itm_chinese_silk',slot_item_small_village,0),
			(item_set_slot,'itm_chinese_silk',slot_item_village,0),
			(item_set_slot,'itm_chinese_silk',slot_item_large_village,0),
			(item_set_slot,'itm_chinese_silk',slot_item_town,0),
			(item_set_slot,'itm_chinese_silk',slot_item_large_town,100),
			(item_set_slot,'itm_chinese_silk',slot_item_city,200),
			(item_set_slot,'itm_chinese_silk',slot_item_port,400),
			(item_set_slot,'itm_chinese_silk',slot_item_jan,0),
			(item_set_slot,'itm_chinese_silk',slot_item_feb,0),
			(item_set_slot,'itm_chinese_silk',slot_item_mar,0),
			(item_set_slot,'itm_chinese_silk',slot_item_apr,0),
			(item_set_slot,'itm_chinese_silk',slot_item_may,0),
			(item_set_slot,'itm_chinese_silk',slot_item_jun,0),
			(item_set_slot,'itm_chinese_silk',slot_item_jul,0),
			(item_set_slot,'itm_chinese_silk',slot_item_aug,0),
			(item_set_slot,'itm_chinese_silk',slot_item_sep,0),
			(item_set_slot,'itm_chinese_silk',slot_item_oct,0),
			(item_set_slot,'itm_chinese_silk',slot_item_nov,0),
			(item_set_slot,'itm_chinese_silk',slot_item_dec,0),
			(item_set_slot,'itm_chinese_silk',slot_item_demand_coefficient,5),

			(item_set_slot,'itm_copper_bar',slot_item_seaside,0),
			(item_set_slot,'itm_copper_bar',slot_item_island,0),
			(item_set_slot,'itm_copper_bar',slot_item_lakeside,0),
			(item_set_slot,'itm_copper_bar',slot_item_lowland,0),
			(item_set_slot,'itm_copper_bar',slot_item_highland,200),
			(item_set_slot,'itm_copper_bar',slot_item_low_valley,0),
			(item_set_slot,'itm_copper_bar',slot_item_high_valley,200),
			(item_set_slot,'itm_copper_bar',slot_item_small_village,0),
			(item_set_slot,'itm_copper_bar',slot_item_village,0),
			(item_set_slot,'itm_copper_bar',slot_item_large_village,0),
			(item_set_slot,'itm_copper_bar',slot_item_town,0),
			(item_set_slot,'itm_copper_bar',slot_item_large_town,100),
			(item_set_slot,'itm_copper_bar',slot_item_city,200),
			(item_set_slot,'itm_copper_bar',slot_item_port,0),
			(item_set_slot,'itm_copper_bar',slot_item_jan,100),
			(item_set_slot,'itm_copper_bar',slot_item_feb,100),
			(item_set_slot,'itm_copper_bar',slot_item_mar,100),
			(item_set_slot,'itm_copper_bar',slot_item_apr,100),
			(item_set_slot,'itm_copper_bar',slot_item_may,100),
			(item_set_slot,'itm_copper_bar',slot_item_jun,100),
			(item_set_slot,'itm_copper_bar',slot_item_jul,100),
			(item_set_slot,'itm_copper_bar',slot_item_aug,100),
			(item_set_slot,'itm_copper_bar',slot_item_sep,100),
			(item_set_slot,'itm_copper_bar',slot_item_oct,100),
			(item_set_slot,'itm_copper_bar',slot_item_nov,100),
			(item_set_slot,'itm_copper_bar',slot_item_dec,100),
			(item_set_slot,'itm_copper_bar',slot_item_demand_coefficient,0),

			(item_set_slot,'itm_copper_bars',slot_item_seaside,0),
			(item_set_slot,'itm_copper_bars',slot_item_island,0),
			(item_set_slot,'itm_copper_bars',slot_item_lakeside,0),
			(item_set_slot,'itm_copper_bars',slot_item_lowland,0),
			(item_set_slot,'itm_copper_bars',slot_item_highland,100),
			(item_set_slot,'itm_copper_bars',slot_item_low_valley,0),
			(item_set_slot,'itm_copper_bars',slot_item_high_valley,100),
			(item_set_slot,'itm_copper_bars',slot_item_small_village,0),
			(item_set_slot,'itm_copper_bars',slot_item_village,0),
			(item_set_slot,'itm_copper_bars',slot_item_large_village,0),
			(item_set_slot,'itm_copper_bars',slot_item_town,0),
			(item_set_slot,'itm_copper_bars',slot_item_large_town,100),
			(item_set_slot,'itm_copper_bars',slot_item_city,200),
			(item_set_slot,'itm_copper_bars',slot_item_port,0),
			(item_set_slot,'itm_copper_bars',slot_item_jan,100),
			(item_set_slot,'itm_copper_bars',slot_item_feb,100),
			(item_set_slot,'itm_copper_bars',slot_item_mar,100),
			(item_set_slot,'itm_copper_bars',slot_item_apr,100),
			(item_set_slot,'itm_copper_bars',slot_item_may,100),
			(item_set_slot,'itm_copper_bars',slot_item_jun,100),
			(item_set_slot,'itm_copper_bars',slot_item_jul,100),
			(item_set_slot,'itm_copper_bars',slot_item_aug,100),
			(item_set_slot,'itm_copper_bars',slot_item_sep,100),
			(item_set_slot,'itm_copper_bars',slot_item_oct,100),
			(item_set_slot,'itm_copper_bars',slot_item_nov,100),
			(item_set_slot,'itm_copper_bars',slot_item_dec,100),
			(item_set_slot,'itm_copper_bars',slot_item_demand_coefficient,0),

			(item_set_slot,'itm_copper_ore',slot_item_seaside,0),
			(item_set_slot,'itm_copper_ore',slot_item_island,0),
			(item_set_slot,'itm_copper_ore',slot_item_lakeside,0),
			(item_set_slot,'itm_copper_ore',slot_item_lowland,0),
			(item_set_slot,'itm_copper_ore',slot_item_highland,100),
			(item_set_slot,'itm_copper_ore',slot_item_low_valley,0),
			(item_set_slot,'itm_copper_ore',slot_item_high_valley,200),
			(item_set_slot,'itm_copper_ore',slot_item_small_village,0),
			(item_set_slot,'itm_copper_ore',slot_item_village,0),
			(item_set_slot,'itm_copper_ore',slot_item_large_village,0),
			(item_set_slot,'itm_copper_ore',slot_item_town,0),
			(item_set_slot,'itm_copper_ore',slot_item_large_town,100),
			(item_set_slot,'itm_copper_ore',slot_item_city,200),
			(item_set_slot,'itm_copper_ore',slot_item_port,0),
			(item_set_slot,'itm_copper_ore',slot_item_jan,0),
			(item_set_slot,'itm_copper_ore',slot_item_feb,0),
			(item_set_slot,'itm_copper_ore',slot_item_mar,0),
			(item_set_slot,'itm_copper_ore',slot_item_apr,0),
			(item_set_slot,'itm_copper_ore',slot_item_may,0),
			(item_set_slot,'itm_copper_ore',slot_item_jun,0),
			(item_set_slot,'itm_copper_ore',slot_item_jul,0),
			(item_set_slot,'itm_copper_ore',slot_item_aug,0),
			(item_set_slot,'itm_copper_ore',slot_item_sep,0),
			(item_set_slot,'itm_copper_ore',slot_item_oct,0),
			(item_set_slot,'itm_copper_ore',slot_item_nov,0),
			(item_set_slot,'itm_copper_ore',slot_item_dec,0),
			(item_set_slot,'itm_copper_ore',slot_item_demand_coefficient,0),

			(item_set_slot,'itm_daikon',slot_item_seaside,0),
			(item_set_slot,'itm_daikon',slot_item_island,0),
			(item_set_slot,'itm_daikon',slot_item_lakeside,0),
			(item_set_slot,'itm_daikon',slot_item_lowland,300),
			(item_set_slot,'itm_daikon',slot_item_highland,0),
			(item_set_slot,'itm_daikon',slot_item_low_valley,0),
			(item_set_slot,'itm_daikon',slot_item_high_valley,0),
			(item_set_slot,'itm_daikon',slot_item_small_village,0),
			(item_set_slot,'itm_daikon',slot_item_village,0),
			(item_set_slot,'itm_daikon',slot_item_large_village,100),
			(item_set_slot,'itm_daikon',slot_item_town,100),
			(item_set_slot,'itm_daikon',slot_item_large_town,0),
			(item_set_slot,'itm_daikon',slot_item_city,0),
			(item_set_slot,'itm_daikon',slot_item_port,0),
			(item_set_slot,'itm_daikon',slot_item_jan,30),
			(item_set_slot,'itm_daikon',slot_item_feb,0),
			(item_set_slot,'itm_daikon',slot_item_mar,0),
			(item_set_slot,'itm_daikon',slot_item_apr,0),
			(item_set_slot,'itm_daikon',slot_item_may,0),
			(item_set_slot,'itm_daikon',slot_item_jun,0),
			(item_set_slot,'itm_daikon',slot_item_jul,0),
			(item_set_slot,'itm_daikon',slot_item_aug,0),
			(item_set_slot,'itm_daikon',slot_item_sep,0),
			(item_set_slot,'itm_daikon',slot_item_oct,0),
			(item_set_slot,'itm_daikon',slot_item_nov,100),
			(item_set_slot,'itm_daikon',slot_item_dec,60),
			(item_set_slot,'itm_daikon',slot_item_demand_coefficient,0),

			(item_set_slot,'itm_dried_beef',slot_item_seaside,0),
			(item_set_slot,'itm_dried_beef',slot_item_island,0),
			(item_set_slot,'itm_dried_beef',slot_item_lakeside,0),
			(item_set_slot,'itm_dried_beef',slot_item_lowland,100),
			(item_set_slot,'itm_dried_beef',slot_item_highland,0),
			(item_set_slot,'itm_dried_beef',slot_item_low_valley,0),
			(item_set_slot,'itm_dried_beef',slot_item_high_valley,0),
			(item_set_slot,'itm_dried_beef',slot_item_small_village,0),
			(item_set_slot,'itm_dried_beef',slot_item_village,0),
			(item_set_slot,'itm_dried_beef',slot_item_large_village,0),
			(item_set_slot,'itm_dried_beef',slot_item_town,0),
			(item_set_slot,'itm_dried_beef',slot_item_large_town,0),
			(item_set_slot,'itm_dried_beef',slot_item_city,0),
			(item_set_slot,'itm_dried_beef',slot_item_port,0),
			(item_set_slot,'itm_dried_beef',slot_item_jan,100),
			(item_set_slot,'itm_dried_beef',slot_item_feb,100),
			(item_set_slot,'itm_dried_beef',slot_item_mar,100),
			(item_set_slot,'itm_dried_beef',slot_item_apr,100),
			(item_set_slot,'itm_dried_beef',slot_item_may,100),
			(item_set_slot,'itm_dried_beef',slot_item_jun,100),
			(item_set_slot,'itm_dried_beef',slot_item_jul,100),
			(item_set_slot,'itm_dried_beef',slot_item_aug,100),
			(item_set_slot,'itm_dried_beef',slot_item_sep,100),
			(item_set_slot,'itm_dried_beef',slot_item_oct,100),
			(item_set_slot,'itm_dried_beef',slot_item_nov,100),
			(item_set_slot,'itm_dried_beef',slot_item_dec,100),
			(item_set_slot,'itm_dried_beef',slot_item_demand_coefficient,0),

			(item_set_slot,'itm_dried_meat',slot_item_seaside,0),
			(item_set_slot,'itm_dried_meat',slot_item_island,0),
			(item_set_slot,'itm_dried_meat',slot_item_lakeside,0),
			(item_set_slot,'itm_dried_meat',slot_item_lowland,0),
			(item_set_slot,'itm_dried_meat',slot_item_highland,100),
			(item_set_slot,'itm_dried_meat',slot_item_low_valley,0),
			(item_set_slot,'itm_dried_meat',slot_item_high_valley,100),
			(item_set_slot,'itm_dried_meat',slot_item_small_village,0),
			(item_set_slot,'itm_dried_meat',slot_item_village,0),
			(item_set_slot,'itm_dried_meat',slot_item_large_village,0),
			(item_set_slot,'itm_dried_meat',slot_item_town,0),
			(item_set_slot,'itm_dried_meat',slot_item_large_town,0),
			(item_set_slot,'itm_dried_meat',slot_item_city,0),
			(item_set_slot,'itm_dried_meat',slot_item_port,0),
			(item_set_slot,'itm_dried_meat',slot_item_jan,100),
			(item_set_slot,'itm_dried_meat',slot_item_feb,100),
			(item_set_slot,'itm_dried_meat',slot_item_mar,100),
			(item_set_slot,'itm_dried_meat',slot_item_apr,100),
			(item_set_slot,'itm_dried_meat',slot_item_may,100),
			(item_set_slot,'itm_dried_meat',slot_item_jun,100),
			(item_set_slot,'itm_dried_meat',slot_item_jul,100),
			(item_set_slot,'itm_dried_meat',slot_item_aug,100),
			(item_set_slot,'itm_dried_meat',slot_item_sep,100),
			(item_set_slot,'itm_dried_meat',slot_item_oct,100),
			(item_set_slot,'itm_dried_meat',slot_item_nov,100),
			(item_set_slot,'itm_dried_meat',slot_item_dec,100),
			(item_set_slot,'itm_dried_meat',slot_item_demand_coefficient,0),

			(item_set_slot,'itm_echizen_paper',slot_item_seaside,0),
			(item_set_slot,'itm_echizen_paper',slot_item_island,0),
			(item_set_slot,'itm_echizen_paper',slot_item_lakeside,0),
			(item_set_slot,'itm_echizen_paper',slot_item_lowland,0),
			(item_set_slot,'itm_echizen_paper',slot_item_highland,0),
			(item_set_slot,'itm_echizen_paper',slot_item_low_valley,0),
			(item_set_slot,'itm_echizen_paper',slot_item_high_valley,0),
			(item_set_slot,'itm_echizen_paper',slot_item_small_village,0),
			(item_set_slot,'itm_echizen_paper',slot_item_village,0),
			(item_set_slot,'itm_echizen_paper',slot_item_large_village,0),
			(item_set_slot,'itm_echizen_paper',slot_item_town,0),
			(item_set_slot,'itm_echizen_paper',slot_item_large_town,0),
			(item_set_slot,'itm_echizen_paper',slot_item_city,0),
			(item_set_slot,'itm_echizen_paper',slot_item_port,0),
			(item_set_slot,'itm_echizen_paper',slot_item_jan,0),
			(item_set_slot,'itm_echizen_paper',slot_item_feb,0),
			(item_set_slot,'itm_echizen_paper',slot_item_mar,0),
			(item_set_slot,'itm_echizen_paper',slot_item_apr,0),
			(item_set_slot,'itm_echizen_paper',slot_item_may,0),
			(item_set_slot,'itm_echizen_paper',slot_item_jun,0),
			(item_set_slot,'itm_echizen_paper',slot_item_jul,0),
			(item_set_slot,'itm_echizen_paper',slot_item_aug,0),
			(item_set_slot,'itm_echizen_paper',slot_item_sep,0),
			(item_set_slot,'itm_echizen_paper',slot_item_oct,0),
			(item_set_slot,'itm_echizen_paper',slot_item_nov,0),
			(item_set_slot,'itm_echizen_paper',slot_item_dec,0),
			(item_set_slot,'itm_echizen_paper',slot_item_demand_coefficient,2),

			(item_set_slot,'itm_eggplant',slot_item_seaside,0),
			(item_set_slot,'itm_eggplant',slot_item_island,0),
			(item_set_slot,'itm_eggplant',slot_item_lakeside,0),
			(item_set_slot,'itm_eggplant',slot_item_lowland,200),
			(item_set_slot,'itm_eggplant',slot_item_highland,0),
			(item_set_slot,'itm_eggplant',slot_item_low_valley,0),
			(item_set_slot,'itm_eggplant',slot_item_high_valley,0),
			(item_set_slot,'itm_eggplant',slot_item_small_village,0),
			(item_set_slot,'itm_eggplant',slot_item_village,0),
			(item_set_slot,'itm_eggplant',slot_item_large_village,100),
			(item_set_slot,'itm_eggplant',slot_item_town,100),
			(item_set_slot,'itm_eggplant',slot_item_large_town,0),
			(item_set_slot,'itm_eggplant',slot_item_city,0),
			(item_set_slot,'itm_eggplant',slot_item_port,0),
			(item_set_slot,'itm_eggplant',slot_item_jan,0),
			(item_set_slot,'itm_eggplant',slot_item_feb,0),
			(item_set_slot,'itm_eggplant',slot_item_mar,0),
			(item_set_slot,'itm_eggplant',slot_item_apr,0),
			(item_set_slot,'itm_eggplant',slot_item_may,0),
			(item_set_slot,'itm_eggplant',slot_item_jun,0),
			(item_set_slot,'itm_eggplant',slot_item_jul,100),
			(item_set_slot,'itm_eggplant',slot_item_aug,60),
			(item_set_slot,'itm_eggplant',slot_item_sep,30),
			(item_set_slot,'itm_eggplant',slot_item_oct,0),
			(item_set_slot,'itm_eggplant',slot_item_nov,0),
			(item_set_slot,'itm_eggplant',slot_item_dec,0),
			(item_set_slot,'itm_eggplant',slot_item_demand_coefficient,0),

			(item_set_slot,'itm_elaborate_furniture',slot_item_seaside,0),
			(item_set_slot,'itm_elaborate_furniture',slot_item_island,0),
			(item_set_slot,'itm_elaborate_furniture',slot_item_lakeside,0),
			(item_set_slot,'itm_elaborate_furniture',slot_item_lowland,0),
			(item_set_slot,'itm_elaborate_furniture',slot_item_highland,100),
			(item_set_slot,'itm_elaborate_furniture',slot_item_low_valley,0),
			(item_set_slot,'itm_elaborate_furniture',slot_item_high_valley,100),
			(item_set_slot,'itm_elaborate_furniture',slot_item_small_village,0),
			(item_set_slot,'itm_elaborate_furniture',slot_item_village,0),
			(item_set_slot,'itm_elaborate_furniture',slot_item_large_village,100),
			(item_set_slot,'itm_elaborate_furniture',slot_item_town,0),
			(item_set_slot,'itm_elaborate_furniture',slot_item_large_town,0),
			(item_set_slot,'itm_elaborate_furniture',slot_item_city,0),
			(item_set_slot,'itm_elaborate_furniture',slot_item_port,0),
			(item_set_slot,'itm_elaborate_furniture',slot_item_jan,100),
			(item_set_slot,'itm_elaborate_furniture',slot_item_feb,100),
			(item_set_slot,'itm_elaborate_furniture',slot_item_mar,100),
			(item_set_slot,'itm_elaborate_furniture',slot_item_apr,100),
			(item_set_slot,'itm_elaborate_furniture',slot_item_may,100),
			(item_set_slot,'itm_elaborate_furniture',slot_item_jun,100),
			(item_set_slot,'itm_elaborate_furniture',slot_item_jul,100),
			(item_set_slot,'itm_elaborate_furniture',slot_item_aug,100),
			(item_set_slot,'itm_elaborate_furniture',slot_item_sep,100),
			(item_set_slot,'itm_elaborate_furniture',slot_item_oct,100),
			(item_set_slot,'itm_elaborate_furniture',slot_item_nov,100),
			(item_set_slot,'itm_elaborate_furniture',slot_item_dec,100),
			(item_set_slot,'itm_elaborate_furniture',slot_item_demand_coefficient,10),

			(item_set_slot,'itm_elaborate_housewares',slot_item_seaside,0),
			(item_set_slot,'itm_elaborate_housewares',slot_item_island,0),
			(item_set_slot,'itm_elaborate_housewares',slot_item_lakeside,0),
			(item_set_slot,'itm_elaborate_housewares',slot_item_lowland,0),
			(item_set_slot,'itm_elaborate_housewares',slot_item_highland,0),
			(item_set_slot,'itm_elaborate_housewares',slot_item_low_valley,0),
			(item_set_slot,'itm_elaborate_housewares',slot_item_high_valley,100),
			(item_set_slot,'itm_elaborate_housewares',slot_item_small_village,0),
			(item_set_slot,'itm_elaborate_housewares',slot_item_village,0),
			(item_set_slot,'itm_elaborate_housewares',slot_item_large_village,100),
			(item_set_slot,'itm_elaborate_housewares',slot_item_town,0),
			(item_set_slot,'itm_elaborate_housewares',slot_item_large_town,0),
			(item_set_slot,'itm_elaborate_housewares',slot_item_city,0),
			(item_set_slot,'itm_elaborate_housewares',slot_item_port,0),
			(item_set_slot,'itm_elaborate_housewares',slot_item_jan,100),
			(item_set_slot,'itm_elaborate_housewares',slot_item_feb,100),
			(item_set_slot,'itm_elaborate_housewares',slot_item_mar,100),
			(item_set_slot,'itm_elaborate_housewares',slot_item_apr,100),
			(item_set_slot,'itm_elaborate_housewares',slot_item_may,100),
			(item_set_slot,'itm_elaborate_housewares',slot_item_jun,100),
			(item_set_slot,'itm_elaborate_housewares',slot_item_jul,100),
			(item_set_slot,'itm_elaborate_housewares',slot_item_aug,100),
			(item_set_slot,'itm_elaborate_housewares',slot_item_sep,100),
			(item_set_slot,'itm_elaborate_housewares',slot_item_oct,100),
			(item_set_slot,'itm_elaborate_housewares',slot_item_nov,100),
			(item_set_slot,'itm_elaborate_housewares',slot_item_dec,100),
			(item_set_slot,'itm_elaborate_housewares',slot_item_demand_coefficient,15),

			(item_set_slot,'itm_elaborate_pottery',slot_item_seaside,0),
			(item_set_slot,'itm_elaborate_pottery',slot_item_island,0),
			(item_set_slot,'itm_elaborate_pottery',slot_item_lakeside,0),
			(item_set_slot,'itm_elaborate_pottery',slot_item_lowland,100),
			(item_set_slot,'itm_elaborate_pottery',slot_item_highland,100),
			(item_set_slot,'itm_elaborate_pottery',slot_item_low_valley,0),
			(item_set_slot,'itm_elaborate_pottery',slot_item_high_valley,0),
			(item_set_slot,'itm_elaborate_pottery',slot_item_small_village,0),
			(item_set_slot,'itm_elaborate_pottery',slot_item_village,0),
			(item_set_slot,'itm_elaborate_pottery',slot_item_large_village,0),
			(item_set_slot,'itm_elaborate_pottery',slot_item_town,0),
			(item_set_slot,'itm_elaborate_pottery',slot_item_large_town,100),
			(item_set_slot,'itm_elaborate_pottery',slot_item_city,200),
			(item_set_slot,'itm_elaborate_pottery',slot_item_port,0),
			(item_set_slot,'itm_elaborate_pottery',slot_item_jan,100),
			(item_set_slot,'itm_elaborate_pottery',slot_item_feb,100),
			(item_set_slot,'itm_elaborate_pottery',slot_item_mar,100),
			(item_set_slot,'itm_elaborate_pottery',slot_item_apr,100),
			(item_set_slot,'itm_elaborate_pottery',slot_item_may,100),
			(item_set_slot,'itm_elaborate_pottery',slot_item_jun,100),
			(item_set_slot,'itm_elaborate_pottery',slot_item_jul,100),
			(item_set_slot,'itm_elaborate_pottery',slot_item_aug,100),
			(item_set_slot,'itm_elaborate_pottery',slot_item_sep,100),
			(item_set_slot,'itm_elaborate_pottery',slot_item_oct,100),
			(item_set_slot,'itm_elaborate_pottery',slot_item_nov,100),
			(item_set_slot,'itm_elaborate_pottery',slot_item_dec,100),
			(item_set_slot,'itm_elaborate_pottery',slot_item_demand_coefficient,3),

			(item_set_slot,'itm_flour',slot_item_seaside,0),
			(item_set_slot,'itm_flour',slot_item_island,0),
			(item_set_slot,'itm_flour',slot_item_lakeside,0),
			(item_set_slot,'itm_flour',slot_item_lowland,0),
			(item_set_slot,'itm_flour',slot_item_highland,0),
			(item_set_slot,'itm_flour',slot_item_low_valley,0),
			(item_set_slot,'itm_flour',slot_item_high_valley,0),
			(item_set_slot,'itm_flour',slot_item_small_village,0),
			(item_set_slot,'itm_flour',slot_item_village,0),
			(item_set_slot,'itm_flour',slot_item_large_village,0),
			(item_set_slot,'itm_flour',slot_item_town,0),
			(item_set_slot,'itm_flour',slot_item_large_town,0),
			(item_set_slot,'itm_flour',slot_item_city,0),
			(item_set_slot,'itm_flour',slot_item_port,0),
			(item_set_slot,'itm_flour',slot_item_jan,0),
			(item_set_slot,'itm_flour',slot_item_feb,0),
			(item_set_slot,'itm_flour',slot_item_mar,0),
			(item_set_slot,'itm_flour',slot_item_apr,0),
			(item_set_slot,'itm_flour',slot_item_may,0),
			(item_set_slot,'itm_flour',slot_item_jun,0),
			(item_set_slot,'itm_flour',slot_item_jul,0),
			(item_set_slot,'itm_flour',slot_item_aug,0),
			(item_set_slot,'itm_flour',slot_item_sep,0),
			(item_set_slot,'itm_flour',slot_item_oct,0),
			(item_set_slot,'itm_flour',slot_item_nov,0),
			(item_set_slot,'itm_flour',slot_item_dec,0),
			(item_set_slot,'itm_flour',slot_item_demand_coefficient,0),

			(item_set_slot,'itm_flute',slot_item_seaside,0),
			(item_set_slot,'itm_flute',slot_item_island,0),
			(item_set_slot,'itm_flute',slot_item_lakeside,0),
			(item_set_slot,'itm_flute',slot_item_lowland,0),
			(item_set_slot,'itm_flute',slot_item_highland,0),
			(item_set_slot,'itm_flute',slot_item_low_valley,0),
			(item_set_slot,'itm_flute',slot_item_high_valley,100),
			(item_set_slot,'itm_flute',slot_item_small_village,0),
			(item_set_slot,'itm_flute',slot_item_village,0),
			(item_set_slot,'itm_flute',slot_item_large_village,0),
			(item_set_slot,'itm_flute',slot_item_town,0),
			(item_set_slot,'itm_flute',slot_item_large_town,100),
			(item_set_slot,'itm_flute',slot_item_city,100),
			(item_set_slot,'itm_flute',slot_item_port,0),
			(item_set_slot,'itm_flute',slot_item_jan,100),
			(item_set_slot,'itm_flute',slot_item_feb,100),
			(item_set_slot,'itm_flute',slot_item_mar,100),
			(item_set_slot,'itm_flute',slot_item_apr,100),
			(item_set_slot,'itm_flute',slot_item_may,100),
			(item_set_slot,'itm_flute',slot_item_jun,100),
			(item_set_slot,'itm_flute',slot_item_jul,100),
			(item_set_slot,'itm_flute',slot_item_aug,100),
			(item_set_slot,'itm_flute',slot_item_sep,100),
			(item_set_slot,'itm_flute',slot_item_oct,100),
			(item_set_slot,'itm_flute',slot_item_nov,100),
			(item_set_slot,'itm_flute',slot_item_dec,100),
			(item_set_slot,'itm_flute',slot_item_demand_coefficient,0),

			(item_set_slot,'itm_folding_screen',slot_item_seaside,0),
			(item_set_slot,'itm_folding_screen',slot_item_island,0),
			(item_set_slot,'itm_folding_screen',slot_item_lakeside,0),
			(item_set_slot,'itm_folding_screen',slot_item_lowland,0),
			(item_set_slot,'itm_folding_screen',slot_item_highland,0),
			(item_set_slot,'itm_folding_screen',slot_item_low_valley,0),
			(item_set_slot,'itm_folding_screen',slot_item_high_valley,0),
			(item_set_slot,'itm_folding_screen',slot_item_small_village,0),
			(item_set_slot,'itm_folding_screen',slot_item_village,0),
			(item_set_slot,'itm_folding_screen',slot_item_large_village,0),
			(item_set_slot,'itm_folding_screen',slot_item_town,0),
			(item_set_slot,'itm_folding_screen',slot_item_large_town,100),
			(item_set_slot,'itm_folding_screen',slot_item_city,100),
			(item_set_slot,'itm_folding_screen',slot_item_port,0),
			(item_set_slot,'itm_folding_screen',slot_item_jan,100),
			(item_set_slot,'itm_folding_screen',slot_item_feb,100),
			(item_set_slot,'itm_folding_screen',slot_item_mar,100),
			(item_set_slot,'itm_folding_screen',slot_item_apr,100),
			(item_set_slot,'itm_folding_screen',slot_item_may,100),
			(item_set_slot,'itm_folding_screen',slot_item_jun,100),
			(item_set_slot,'itm_folding_screen',slot_item_jul,100),
			(item_set_slot,'itm_folding_screen',slot_item_aug,100),
			(item_set_slot,'itm_folding_screen',slot_item_sep,100),
			(item_set_slot,'itm_folding_screen',slot_item_oct,100),
			(item_set_slot,'itm_folding_screen',slot_item_nov,100),
			(item_set_slot,'itm_folding_screen',slot_item_dec,100),
			(item_set_slot,'itm_folding_screen',slot_item_demand_coefficient,0),

			(item_set_slot,'itm_foreign_goods',slot_item_seaside,0),
			(item_set_slot,'itm_foreign_goods',slot_item_island,0),
			(item_set_slot,'itm_foreign_goods',slot_item_lakeside,0),
			(item_set_slot,'itm_foreign_goods',slot_item_lowland,0),
			(item_set_slot,'itm_foreign_goods',slot_item_highland,0),
			(item_set_slot,'itm_foreign_goods',slot_item_low_valley,0),
			(item_set_slot,'itm_foreign_goods',slot_item_high_valley,0),
			(item_set_slot,'itm_foreign_goods',slot_item_small_village,0),
			(item_set_slot,'itm_foreign_goods',slot_item_village,0),
			(item_set_slot,'itm_foreign_goods',slot_item_large_village,0),
			(item_set_slot,'itm_foreign_goods',slot_item_town,0),
			(item_set_slot,'itm_foreign_goods',slot_item_large_town,0),
			(item_set_slot,'itm_foreign_goods',slot_item_city,0),
			(item_set_slot,'itm_foreign_goods',slot_item_port,100),
			(item_set_slot,'itm_foreign_goods',slot_item_jan,0),
			(item_set_slot,'itm_foreign_goods',slot_item_feb,0),
			(item_set_slot,'itm_foreign_goods',slot_item_mar,0),
			(item_set_slot,'itm_foreign_goods',slot_item_apr,0),
			(item_set_slot,'itm_foreign_goods',slot_item_may,0),
			(item_set_slot,'itm_foreign_goods',slot_item_jun,0),
			(item_set_slot,'itm_foreign_goods',slot_item_jul,0),
			(item_set_slot,'itm_foreign_goods',slot_item_aug,0),
			(item_set_slot,'itm_foreign_goods',slot_item_sep,0),
			(item_set_slot,'itm_foreign_goods',slot_item_oct,0),
			(item_set_slot,'itm_foreign_goods',slot_item_nov,0),
			(item_set_slot,'itm_foreign_goods',slot_item_dec,0),
			(item_set_slot,'itm_foreign_goods',slot_item_demand_coefficient,5),

			(item_set_slot,'itm_furniture',slot_item_seaside,100),
			(item_set_slot,'itm_furniture',slot_item_island,0),
			(item_set_slot,'itm_furniture',slot_item_lakeside,0),
			(item_set_slot,'itm_furniture',slot_item_lowland,100),
			(item_set_slot,'itm_furniture',slot_item_highland,200),
			(item_set_slot,'itm_furniture',slot_item_low_valley,100),
			(item_set_slot,'itm_furniture',slot_item_high_valley,200),
			(item_set_slot,'itm_furniture',slot_item_small_village,0),
			(item_set_slot,'itm_furniture',slot_item_village,0),
			(item_set_slot,'itm_furniture',slot_item_large_village,200),
			(item_set_slot,'itm_furniture',slot_item_town,0),
			(item_set_slot,'itm_furniture',slot_item_large_town,0),
			(item_set_slot,'itm_furniture',slot_item_city,0),
			(item_set_slot,'itm_furniture',slot_item_port,0),
			(item_set_slot,'itm_furniture',slot_item_jan,100),
			(item_set_slot,'itm_furniture',slot_item_feb,100),
			(item_set_slot,'itm_furniture',slot_item_mar,100),
			(item_set_slot,'itm_furniture',slot_item_apr,100),
			(item_set_slot,'itm_furniture',slot_item_may,100),
			(item_set_slot,'itm_furniture',slot_item_jun,100),
			(item_set_slot,'itm_furniture',slot_item_jul,100),
			(item_set_slot,'itm_furniture',slot_item_aug,100),
			(item_set_slot,'itm_furniture',slot_item_sep,100),
			(item_set_slot,'itm_furniture',slot_item_oct,100),
			(item_set_slot,'itm_furniture',slot_item_nov,100),
			(item_set_slot,'itm_furniture',slot_item_dec,100),
			(item_set_slot,'itm_furniture',slot_item_demand_coefficient,85),

			(item_set_slot,'itm_furs',slot_item_seaside,0),
			(item_set_slot,'itm_furs',slot_item_island,0),
			(item_set_slot,'itm_furs',slot_item_lakeside,0),
			(item_set_slot,'itm_furs',slot_item_lowland,0),
			(item_set_slot,'itm_furs',slot_item_highland,0),
			(item_set_slot,'itm_furs',slot_item_low_valley,0),
			(item_set_slot,'itm_furs',slot_item_high_valley,0),
			(item_set_slot,'itm_furs',slot_item_small_village,0),
			(item_set_slot,'itm_furs',slot_item_village,0),
			(item_set_slot,'itm_furs',slot_item_large_village,0),
			(item_set_slot,'itm_furs',slot_item_town,0),
			(item_set_slot,'itm_furs',slot_item_large_town,0),
			(item_set_slot,'itm_furs',slot_item_city,0),
			(item_set_slot,'itm_furs',slot_item_port,0),
			(item_set_slot,'itm_furs',slot_item_jan,0),
			(item_set_slot,'itm_furs',slot_item_feb,0),
			(item_set_slot,'itm_furs',slot_item_mar,0),
			(item_set_slot,'itm_furs',slot_item_apr,0),
			(item_set_slot,'itm_furs',slot_item_may,0),
			(item_set_slot,'itm_furs',slot_item_jun,0),
			(item_set_slot,'itm_furs',slot_item_jul,0),
			(item_set_slot,'itm_furs',slot_item_aug,0),
			(item_set_slot,'itm_furs',slot_item_sep,0),
			(item_set_slot,'itm_furs',slot_item_oct,0),
			(item_set_slot,'itm_furs',slot_item_nov,0),
			(item_set_slot,'itm_furs',slot_item_dec,0),
			(item_set_slot,'itm_furs',slot_item_demand_coefficient,0),

			(item_set_slot,'itm_genji_monogatari',slot_item_seaside,0),
			(item_set_slot,'itm_genji_monogatari',slot_item_island,0),
			(item_set_slot,'itm_genji_monogatari',slot_item_lakeside,0),
			(item_set_slot,'itm_genji_monogatari',slot_item_lowland,0),
			(item_set_slot,'itm_genji_monogatari',slot_item_highland,0),
			(item_set_slot,'itm_genji_monogatari',slot_item_low_valley,0),
			(item_set_slot,'itm_genji_monogatari',slot_item_high_valley,0),
			(item_set_slot,'itm_genji_monogatari',slot_item_small_village,0),
			(item_set_slot,'itm_genji_monogatari',slot_item_village,0),
			(item_set_slot,'itm_genji_monogatari',slot_item_large_village,0),
			(item_set_slot,'itm_genji_monogatari',slot_item_town,0),
			(item_set_slot,'itm_genji_monogatari',slot_item_large_town,100),
			(item_set_slot,'itm_genji_monogatari',slot_item_city,200),
			(item_set_slot,'itm_genji_monogatari',slot_item_port,0),
			(item_set_slot,'itm_genji_monogatari',slot_item_jan,100),
			(item_set_slot,'itm_genji_monogatari',slot_item_feb,100),
			(item_set_slot,'itm_genji_monogatari',slot_item_mar,100),
			(item_set_slot,'itm_genji_monogatari',slot_item_apr,100),
			(item_set_slot,'itm_genji_monogatari',slot_item_may,100),
			(item_set_slot,'itm_genji_monogatari',slot_item_jun,100),
			(item_set_slot,'itm_genji_monogatari',slot_item_jul,100),
			(item_set_slot,'itm_genji_monogatari',slot_item_aug,100),
			(item_set_slot,'itm_genji_monogatari',slot_item_sep,100),
			(item_set_slot,'itm_genji_monogatari',slot_item_oct,100),
			(item_set_slot,'itm_genji_monogatari',slot_item_nov,100),
			(item_set_slot,'itm_genji_monogatari',slot_item_dec,100),
			(item_set_slot,'itm_genji_monogatari',slot_item_demand_coefficient,0),

			(item_set_slot,'itm_ginger',slot_item_seaside,0),
			(item_set_slot,'itm_ginger',slot_item_island,0),
			(item_set_slot,'itm_ginger',slot_item_lakeside,0),
			(item_set_slot,'itm_ginger',slot_item_lowland,200),
			(item_set_slot,'itm_ginger',slot_item_highland,0),
			(item_set_slot,'itm_ginger',slot_item_low_valley,0),
			(item_set_slot,'itm_ginger',slot_item_high_valley,0),
			(item_set_slot,'itm_ginger',slot_item_small_village,0),
			(item_set_slot,'itm_ginger',slot_item_village,0),
			(item_set_slot,'itm_ginger',slot_item_large_village,100),
			(item_set_slot,'itm_ginger',slot_item_town,100),
			(item_set_slot,'itm_ginger',slot_item_large_town,0),
			(item_set_slot,'itm_ginger',slot_item_city,0),
			(item_set_slot,'itm_ginger',slot_item_port,0),
			(item_set_slot,'itm_ginger',slot_item_jan,100),
			(item_set_slot,'itm_ginger',slot_item_feb,100),
			(item_set_slot,'itm_ginger',slot_item_mar,100),
			(item_set_slot,'itm_ginger',slot_item_apr,100),
			(item_set_slot,'itm_ginger',slot_item_may,100),
			(item_set_slot,'itm_ginger',slot_item_jun,100),
			(item_set_slot,'itm_ginger',slot_item_jul,100),
			(item_set_slot,'itm_ginger',slot_item_aug,100),
			(item_set_slot,'itm_ginger',slot_item_sep,100),
			(item_set_slot,'itm_ginger',slot_item_oct,100),
			(item_set_slot,'itm_ginger',slot_item_nov,100),
			(item_set_slot,'itm_ginger',slot_item_dec,100),
			(item_set_slot,'itm_ginger',slot_item_demand_coefficient,0),

			(item_set_slot,'itm_gold',slot_item_seaside,0),
			(item_set_slot,'itm_gold',slot_item_island,0),
			(item_set_slot,'itm_gold',slot_item_lakeside,0),
			(item_set_slot,'itm_gold',slot_item_lowland,0),
			(item_set_slot,'itm_gold',slot_item_highland,0),
			(item_set_slot,'itm_gold',slot_item_low_valley,0),
			(item_set_slot,'itm_gold',slot_item_high_valley,0),
			(item_set_slot,'itm_gold',slot_item_small_village,0),
			(item_set_slot,'itm_gold',slot_item_village,100),
			(item_set_slot,'itm_gold',slot_item_large_village,0),
			(item_set_slot,'itm_gold',slot_item_town,0),
			(item_set_slot,'itm_gold',slot_item_large_town,0),
			(item_set_slot,'itm_gold',slot_item_city,0),
			(item_set_slot,'itm_gold',slot_item_port,0),
			(item_set_slot,'itm_gold',slot_item_jan,0),
			(item_set_slot,'itm_gold',slot_item_feb,0),
			(item_set_slot,'itm_gold',slot_item_mar,0),
			(item_set_slot,'itm_gold',slot_item_apr,0),
			(item_set_slot,'itm_gold',slot_item_may,0),
			(item_set_slot,'itm_gold',slot_item_jun,0),
			(item_set_slot,'itm_gold',slot_item_jul,0),
			(item_set_slot,'itm_gold',slot_item_aug,0),
			(item_set_slot,'itm_gold',slot_item_sep,0),
			(item_set_slot,'itm_gold',slot_item_oct,0),
			(item_set_slot,'itm_gold',slot_item_nov,0),
			(item_set_slot,'itm_gold',slot_item_dec,0),
			(item_set_slot,'itm_gold',slot_item_demand_coefficient,0),

			(item_set_slot,'itm_heike_monogatari',slot_item_seaside,0),
			(item_set_slot,'itm_heike_monogatari',slot_item_island,0),
			(item_set_slot,'itm_heike_monogatari',slot_item_lakeside,0),
			(item_set_slot,'itm_heike_monogatari',slot_item_lowland,0),
			(item_set_slot,'itm_heike_monogatari',slot_item_highland,0),
			(item_set_slot,'itm_heike_monogatari',slot_item_low_valley,0),
			(item_set_slot,'itm_heike_monogatari',slot_item_high_valley,0),
			(item_set_slot,'itm_heike_monogatari',slot_item_small_village,0),
			(item_set_slot,'itm_heike_monogatari',slot_item_village,0),
			(item_set_slot,'itm_heike_monogatari',slot_item_large_village,0),
			(item_set_slot,'itm_heike_monogatari',slot_item_town,0),
			(item_set_slot,'itm_heike_monogatari',slot_item_large_town,100),
			(item_set_slot,'itm_heike_monogatari',slot_item_city,200),
			(item_set_slot,'itm_heike_monogatari',slot_item_port,0),
			(item_set_slot,'itm_heike_monogatari',slot_item_jan,100),
			(item_set_slot,'itm_heike_monogatari',slot_item_feb,100),
			(item_set_slot,'itm_heike_monogatari',slot_item_mar,100),
			(item_set_slot,'itm_heike_monogatari',slot_item_apr,100),
			(item_set_slot,'itm_heike_monogatari',slot_item_may,100),
			(item_set_slot,'itm_heike_monogatari',slot_item_jun,100),
			(item_set_slot,'itm_heike_monogatari',slot_item_jul,100),
			(item_set_slot,'itm_heike_monogatari',slot_item_aug,100),
			(item_set_slot,'itm_heike_monogatari',slot_item_sep,100),
			(item_set_slot,'itm_heike_monogatari',slot_item_oct,100),
			(item_set_slot,'itm_heike_monogatari',slot_item_nov,100),
			(item_set_slot,'itm_heike_monogatari',slot_item_dec,100),
			(item_set_slot,'itm_heike_monogatari',slot_item_demand_coefficient,0),

			(item_set_slot,'itm_hemp',slot_item_seaside,0),
			(item_set_slot,'itm_hemp',slot_item_island,0),
			(item_set_slot,'itm_hemp',slot_item_lakeside,0),
			(item_set_slot,'itm_hemp',slot_item_lowland,200),
			(item_set_slot,'itm_hemp',slot_item_highland,200),
			(item_set_slot,'itm_hemp',slot_item_low_valley,0),
			(item_set_slot,'itm_hemp',slot_item_high_valley,0),
			(item_set_slot,'itm_hemp',slot_item_small_village,0),
			(item_set_slot,'itm_hemp',slot_item_village,0),
			(item_set_slot,'itm_hemp',slot_item_large_village,100),
			(item_set_slot,'itm_hemp',slot_item_town,100),
			(item_set_slot,'itm_hemp',slot_item_large_town,0),
			(item_set_slot,'itm_hemp',slot_item_city,0),
			(item_set_slot,'itm_hemp',slot_item_port,0),
			(item_set_slot,'itm_hemp',slot_item_jan,100),
			(item_set_slot,'itm_hemp',slot_item_feb,100),
			(item_set_slot,'itm_hemp',slot_item_mar,100),
			(item_set_slot,'itm_hemp',slot_item_apr,100),
			(item_set_slot,'itm_hemp',slot_item_may,100),
			(item_set_slot,'itm_hemp',slot_item_jun,100),
			(item_set_slot,'itm_hemp',slot_item_jul,100),
			(item_set_slot,'itm_hemp',slot_item_aug,100),
			(item_set_slot,'itm_hemp',slot_item_sep,100),
			(item_set_slot,'itm_hemp',slot_item_oct,100),
			(item_set_slot,'itm_hemp',slot_item_nov,100),
			(item_set_slot,'itm_hemp',slot_item_dec,100),
			(item_set_slot,'itm_hemp',slot_item_demand_coefficient,1000),

			(item_set_slot,'itm_housewares',slot_item_seaside,0),
			(item_set_slot,'itm_housewares',slot_item_island,0),
			(item_set_slot,'itm_housewares',slot_item_lakeside,100),
			(item_set_slot,'itm_housewares',slot_item_lowland,100),
			(item_set_slot,'itm_housewares',slot_item_highland,200),
			(item_set_slot,'itm_housewares',slot_item_low_valley,100),
			(item_set_slot,'itm_housewares',slot_item_high_valley,200),
			(item_set_slot,'itm_housewares',slot_item_small_village,0),
			(item_set_slot,'itm_housewares',slot_item_village,0),
			(item_set_slot,'itm_housewares',slot_item_large_village,100),
			(item_set_slot,'itm_housewares',slot_item_town,0),
			(item_set_slot,'itm_housewares',slot_item_large_town,0),
			(item_set_slot,'itm_housewares',slot_item_city,0),
			(item_set_slot,'itm_housewares',slot_item_port,0),
			(item_set_slot,'itm_housewares',slot_item_jan,100),
			(item_set_slot,'itm_housewares',slot_item_feb,100),
			(item_set_slot,'itm_housewares',slot_item_mar,100),
			(item_set_slot,'itm_housewares',slot_item_apr,100),
			(item_set_slot,'itm_housewares',slot_item_may,100),
			(item_set_slot,'itm_housewares',slot_item_jun,100),
			(item_set_slot,'itm_housewares',slot_item_jul,100),
			(item_set_slot,'itm_housewares',slot_item_aug,100),
			(item_set_slot,'itm_housewares',slot_item_sep,100),
			(item_set_slot,'itm_housewares',slot_item_oct,100),
			(item_set_slot,'itm_housewares',slot_item_nov,100),
			(item_set_slot,'itm_housewares',slot_item_dec,100),
			(item_set_slot,'itm_housewares',slot_item_demand_coefficient,50),

			(item_set_slot,'itm_imported_spices',slot_item_seaside,0),
			(item_set_slot,'itm_imported_spices',slot_item_island,0),
			(item_set_slot,'itm_imported_spices',slot_item_lakeside,0),
			(item_set_slot,'itm_imported_spices',slot_item_lowland,0),
			(item_set_slot,'itm_imported_spices',slot_item_highland,0),
			(item_set_slot,'itm_imported_spices',slot_item_low_valley,0),
			(item_set_slot,'itm_imported_spices',slot_item_high_valley,0),
			(item_set_slot,'itm_imported_spices',slot_item_small_village,0),
			(item_set_slot,'itm_imported_spices',slot_item_village,0),
			(item_set_slot,'itm_imported_spices',slot_item_large_village,0),
			(item_set_slot,'itm_imported_spices',slot_item_town,0),
			(item_set_slot,'itm_imported_spices',slot_item_large_town,0),
			(item_set_slot,'itm_imported_spices',slot_item_city,100),
			(item_set_slot,'itm_imported_spices',slot_item_port,200),
			(item_set_slot,'itm_imported_spices',slot_item_jan,0),
			(item_set_slot,'itm_imported_spices',slot_item_feb,0),
			(item_set_slot,'itm_imported_spices',slot_item_mar,0),
			(item_set_slot,'itm_imported_spices',slot_item_apr,0),
			(item_set_slot,'itm_imported_spices',slot_item_may,0),
			(item_set_slot,'itm_imported_spices',slot_item_jun,0),
			(item_set_slot,'itm_imported_spices',slot_item_jul,0),
			(item_set_slot,'itm_imported_spices',slot_item_aug,0),
			(item_set_slot,'itm_imported_spices',slot_item_sep,0),
			(item_set_slot,'itm_imported_spices',slot_item_oct,0),
			(item_set_slot,'itm_imported_spices',slot_item_nov,0),
			(item_set_slot,'itm_imported_spices',slot_item_dec,0),
			(item_set_slot,'itm_imported_spices',slot_item_demand_coefficient,5),

			(item_set_slot,'itm_imported_tea',slot_item_seaside,0),
			(item_set_slot,'itm_imported_tea',slot_item_island,0),
			(item_set_slot,'itm_imported_tea',slot_item_lakeside,0),
			(item_set_slot,'itm_imported_tea',slot_item_lowland,0),
			(item_set_slot,'itm_imported_tea',slot_item_highland,0),
			(item_set_slot,'itm_imported_tea',slot_item_low_valley,0),
			(item_set_slot,'itm_imported_tea',slot_item_high_valley,0),
			(item_set_slot,'itm_imported_tea',slot_item_small_village,0),
			(item_set_slot,'itm_imported_tea',slot_item_village,0),
			(item_set_slot,'itm_imported_tea',slot_item_large_village,0),
			(item_set_slot,'itm_imported_tea',slot_item_town,0),
			(item_set_slot,'itm_imported_tea',slot_item_large_town,100),
			(item_set_slot,'itm_imported_tea',slot_item_city,200),
			(item_set_slot,'itm_imported_tea',slot_item_port,400),
			(item_set_slot,'itm_imported_tea',slot_item_jan,0),
			(item_set_slot,'itm_imported_tea',slot_item_feb,0),
			(item_set_slot,'itm_imported_tea',slot_item_mar,0),
			(item_set_slot,'itm_imported_tea',slot_item_apr,0),
			(item_set_slot,'itm_imported_tea',slot_item_may,0),
			(item_set_slot,'itm_imported_tea',slot_item_jun,0),
			(item_set_slot,'itm_imported_tea',slot_item_jul,0),
			(item_set_slot,'itm_imported_tea',slot_item_aug,0),
			(item_set_slot,'itm_imported_tea',slot_item_sep,0),
			(item_set_slot,'itm_imported_tea',slot_item_oct,0),
			(item_set_slot,'itm_imported_tea',slot_item_nov,0),
			(item_set_slot,'itm_imported_tea',slot_item_dec,0),
			(item_set_slot,'itm_imported_tea',slot_item_demand_coefficient,10),

			(item_set_slot,'itm_ink',slot_item_seaside,0),
			(item_set_slot,'itm_ink',slot_item_island,0),
			(item_set_slot,'itm_ink',slot_item_lakeside,0),
			(item_set_slot,'itm_ink',slot_item_lowland,100),
			(item_set_slot,'itm_ink',slot_item_highland,200),
			(item_set_slot,'itm_ink',slot_item_low_valley,300),
			(item_set_slot,'itm_ink',slot_item_high_valley,200),
			(item_set_slot,'itm_ink',slot_item_small_village,0),
			(item_set_slot,'itm_ink',slot_item_village,0),
			(item_set_slot,'itm_ink',slot_item_large_village,0),
			(item_set_slot,'itm_ink',slot_item_town,0),
			(item_set_slot,'itm_ink',slot_item_large_town,0),
			(item_set_slot,'itm_ink',slot_item_city,0),
			(item_set_slot,'itm_ink',slot_item_port,0),
			(item_set_slot,'itm_ink',slot_item_jan,70),
			(item_set_slot,'itm_ink',slot_item_feb,60),
			(item_set_slot,'itm_ink',slot_item_mar,50),
			(item_set_slot,'itm_ink',slot_item_apr,40),
			(item_set_slot,'itm_ink',slot_item_may,30),
			(item_set_slot,'itm_ink',slot_item_jun,20),
			(item_set_slot,'itm_ink',slot_item_jul,10),
			(item_set_slot,'itm_ink',slot_item_aug,10),
			(item_set_slot,'itm_ink',slot_item_sep,100),
			(item_set_slot,'itm_ink',slot_item_oct,100),
			(item_set_slot,'itm_ink',slot_item_nov,90),
			(item_set_slot,'itm_ink',slot_item_dec,80),
			(item_set_slot,'itm_ink',slot_item_demand_coefficient,50),

			(item_set_slot,'itm_ink_sticks',slot_item_seaside,0),
			(item_set_slot,'itm_ink_sticks',slot_item_island,0),
			(item_set_slot,'itm_ink_sticks',slot_item_lakeside,0),
			(item_set_slot,'itm_ink_sticks',slot_item_lowland,0),
			(item_set_slot,'itm_ink_sticks',slot_item_highland,200),
			(item_set_slot,'itm_ink_sticks',slot_item_low_valley,0),
			(item_set_slot,'itm_ink_sticks',slot_item_high_valley,0),
			(item_set_slot,'itm_ink_sticks',slot_item_small_village,0),
			(item_set_slot,'itm_ink_sticks',slot_item_village,0),
			(item_set_slot,'itm_ink_sticks',slot_item_large_village,0),
			(item_set_slot,'itm_ink_sticks',slot_item_town,100),
			(item_set_slot,'itm_ink_sticks',slot_item_large_town,100),
			(item_set_slot,'itm_ink_sticks',slot_item_city,200),
			(item_set_slot,'itm_ink_sticks',slot_item_port,0),
			(item_set_slot,'itm_ink_sticks',slot_item_jan,100),
			(item_set_slot,'itm_ink_sticks',slot_item_feb,100),
			(item_set_slot,'itm_ink_sticks',slot_item_mar,100),
			(item_set_slot,'itm_ink_sticks',slot_item_apr,100),
			(item_set_slot,'itm_ink_sticks',slot_item_may,100),
			(item_set_slot,'itm_ink_sticks',slot_item_jun,100),
			(item_set_slot,'itm_ink_sticks',slot_item_jul,100),
			(item_set_slot,'itm_ink_sticks',slot_item_aug,100),
			(item_set_slot,'itm_ink_sticks',slot_item_sep,100),
			(item_set_slot,'itm_ink_sticks',slot_item_oct,100),
			(item_set_slot,'itm_ink_sticks',slot_item_nov,100),
			(item_set_slot,'itm_ink_sticks',slot_item_dec,100),
			(item_set_slot,'itm_ink_sticks',slot_item_demand_coefficient,30),

			(item_set_slot,'itm_inkstones',slot_item_seaside,0),
			(item_set_slot,'itm_inkstones',slot_item_island,0),
			(item_set_slot,'itm_inkstones',slot_item_lakeside,0),
			(item_set_slot,'itm_inkstones',slot_item_lowland,0),
			(item_set_slot,'itm_inkstones',slot_item_highland,0),
			(item_set_slot,'itm_inkstones',slot_item_low_valley,0),
			(item_set_slot,'itm_inkstones',slot_item_high_valley,100),
			(item_set_slot,'itm_inkstones',slot_item_small_village,0),
			(item_set_slot,'itm_inkstones',slot_item_village,0),
			(item_set_slot,'itm_inkstones',slot_item_large_village,100),
			(item_set_slot,'itm_inkstones',slot_item_town,0),
			(item_set_slot,'itm_inkstones',slot_item_large_town,0),
			(item_set_slot,'itm_inkstones',slot_item_city,100),
			(item_set_slot,'itm_inkstones',slot_item_port,0),
			(item_set_slot,'itm_inkstones',slot_item_jan,100),
			(item_set_slot,'itm_inkstones',slot_item_feb,100),
			(item_set_slot,'itm_inkstones',slot_item_mar,100),
			(item_set_slot,'itm_inkstones',slot_item_apr,100),
			(item_set_slot,'itm_inkstones',slot_item_may,100),
			(item_set_slot,'itm_inkstones',slot_item_jun,100),
			(item_set_slot,'itm_inkstones',slot_item_jul,100),
			(item_set_slot,'itm_inkstones',slot_item_aug,100),
			(item_set_slot,'itm_inkstones',slot_item_sep,100),
			(item_set_slot,'itm_inkstones',slot_item_oct,100),
			(item_set_slot,'itm_inkstones',slot_item_nov,100),
			(item_set_slot,'itm_inkstones',slot_item_dec,100),
			(item_set_slot,'itm_inkstones',slot_item_demand_coefficient,30),

			(item_set_slot,'itm_iron_bar',slot_item_seaside,0),
			(item_set_slot,'itm_iron_bar',slot_item_island,0),
			(item_set_slot,'itm_iron_bar',slot_item_lakeside,0),
			(item_set_slot,'itm_iron_bar',slot_item_lowland,0),
			(item_set_slot,'itm_iron_bar',slot_item_highland,200),
			(item_set_slot,'itm_iron_bar',slot_item_low_valley,0),
			(item_set_slot,'itm_iron_bar',slot_item_high_valley,200),
			(item_set_slot,'itm_iron_bar',slot_item_small_village,0),
			(item_set_slot,'itm_iron_bar',slot_item_village,0),
			(item_set_slot,'itm_iron_bar',slot_item_large_village,0),
			(item_set_slot,'itm_iron_bar',slot_item_town,0),
			(item_set_slot,'itm_iron_bar',slot_item_large_town,100),
			(item_set_slot,'itm_iron_bar',slot_item_city,200),
			(item_set_slot,'itm_iron_bar',slot_item_port,0),
			(item_set_slot,'itm_iron_bar',slot_item_jan,100),
			(item_set_slot,'itm_iron_bar',slot_item_feb,100),
			(item_set_slot,'itm_iron_bar',slot_item_mar,100),
			(item_set_slot,'itm_iron_bar',slot_item_apr,100),
			(item_set_slot,'itm_iron_bar',slot_item_may,100),
			(item_set_slot,'itm_iron_bar',slot_item_jun,100),
			(item_set_slot,'itm_iron_bar',slot_item_jul,100),
			(item_set_slot,'itm_iron_bar',slot_item_aug,100),
			(item_set_slot,'itm_iron_bar',slot_item_sep,100),
			(item_set_slot,'itm_iron_bar',slot_item_oct,100),
			(item_set_slot,'itm_iron_bar',slot_item_nov,100),
			(item_set_slot,'itm_iron_bar',slot_item_dec,100),
			(item_set_slot,'itm_iron_bar',slot_item_demand_coefficient,0),

			(item_set_slot,'itm_iron_bars',slot_item_seaside,0),
			(item_set_slot,'itm_iron_bars',slot_item_island,0),
			(item_set_slot,'itm_iron_bars',slot_item_lakeside,0),
			(item_set_slot,'itm_iron_bars',slot_item_lowland,0),
			(item_set_slot,'itm_iron_bars',slot_item_highland,100),
			(item_set_slot,'itm_iron_bars',slot_item_low_valley,0),
			(item_set_slot,'itm_iron_bars',slot_item_high_valley,100),
			(item_set_slot,'itm_iron_bars',slot_item_small_village,0),
			(item_set_slot,'itm_iron_bars',slot_item_village,0),
			(item_set_slot,'itm_iron_bars',slot_item_large_village,0),
			(item_set_slot,'itm_iron_bars',slot_item_town,0),
			(item_set_slot,'itm_iron_bars',slot_item_large_town,100),
			(item_set_slot,'itm_iron_bars',slot_item_city,100),
			(item_set_slot,'itm_iron_bars',slot_item_port,0),
			(item_set_slot,'itm_iron_bars',slot_item_jan,0),
			(item_set_slot,'itm_iron_bars',slot_item_feb,0),
			(item_set_slot,'itm_iron_bars',slot_item_mar,0),
			(item_set_slot,'itm_iron_bars',slot_item_apr,0),
			(item_set_slot,'itm_iron_bars',slot_item_may,0),
			(item_set_slot,'itm_iron_bars',slot_item_jun,0),
			(item_set_slot,'itm_iron_bars',slot_item_jul,0),
			(item_set_slot,'itm_iron_bars',slot_item_aug,0),
			(item_set_slot,'itm_iron_bars',slot_item_sep,0),
			(item_set_slot,'itm_iron_bars',slot_item_oct,0),
			(item_set_slot,'itm_iron_bars',slot_item_nov,0),
			(item_set_slot,'itm_iron_bars',slot_item_dec,0),
			(item_set_slot,'itm_iron_bars',slot_item_demand_coefficient,0),

			(item_set_slot,'itm_iron_ore',slot_item_seaside,0),
			(item_set_slot,'itm_iron_ore',slot_item_island,0),
			(item_set_slot,'itm_iron_ore',slot_item_lakeside,0),
			(item_set_slot,'itm_iron_ore',slot_item_lowland,0),
			(item_set_slot,'itm_iron_ore',slot_item_highland,100),
			(item_set_slot,'itm_iron_ore',slot_item_low_valley,0),
			(item_set_slot,'itm_iron_ore',slot_item_high_valley,100),
			(item_set_slot,'itm_iron_ore',slot_item_small_village,0),
			(item_set_slot,'itm_iron_ore',slot_item_village,0),
			(item_set_slot,'itm_iron_ore',slot_item_large_village,0),
			(item_set_slot,'itm_iron_ore',slot_item_town,0),
			(item_set_slot,'itm_iron_ore',slot_item_large_town,0),
			(item_set_slot,'itm_iron_ore',slot_item_city,100),
			(item_set_slot,'itm_iron_ore',slot_item_port,0),
			(item_set_slot,'itm_iron_ore',slot_item_jan,0),
			(item_set_slot,'itm_iron_ore',slot_item_feb,0),
			(item_set_slot,'itm_iron_ore',slot_item_mar,0),
			(item_set_slot,'itm_iron_ore',slot_item_apr,0),
			(item_set_slot,'itm_iron_ore',slot_item_may,0),
			(item_set_slot,'itm_iron_ore',slot_item_jun,0),
			(item_set_slot,'itm_iron_ore',slot_item_jul,0),
			(item_set_slot,'itm_iron_ore',slot_item_aug,0),
			(item_set_slot,'itm_iron_ore',slot_item_sep,0),
			(item_set_slot,'itm_iron_ore',slot_item_oct,0),
			(item_set_slot,'itm_iron_ore',slot_item_nov,0),
			(item_set_slot,'itm_iron_ore',slot_item_dec,0),
			(item_set_slot,'itm_iron_ore',slot_item_demand_coefficient,0),

			(item_set_slot,'itm_jodo_shinsu_charm',slot_item_seaside,0),
			(item_set_slot,'itm_jodo_shinsu_charm',slot_item_island,0),
			(item_set_slot,'itm_jodo_shinsu_charm',slot_item_lakeside,0),
			(item_set_slot,'itm_jodo_shinsu_charm',slot_item_lowland,0),
			(item_set_slot,'itm_jodo_shinsu_charm',slot_item_highland,0),
			(item_set_slot,'itm_jodo_shinsu_charm',slot_item_low_valley,0),
			(item_set_slot,'itm_jodo_shinsu_charm',slot_item_high_valley,0),
			(item_set_slot,'itm_jodo_shinsu_charm',slot_item_small_village,0),
			(item_set_slot,'itm_jodo_shinsu_charm',slot_item_village,0),
			(item_set_slot,'itm_jodo_shinsu_charm',slot_item_large_village,100),
			(item_set_slot,'itm_jodo_shinsu_charm',slot_item_town,0),
			(item_set_slot,'itm_jodo_shinsu_charm',slot_item_large_town,0),
			(item_set_slot,'itm_jodo_shinsu_charm',slot_item_city,0),
			(item_set_slot,'itm_jodo_shinsu_charm',slot_item_port,0),
			(item_set_slot,'itm_jodo_shinsu_charm',slot_item_jan,100),
			(item_set_slot,'itm_jodo_shinsu_charm',slot_item_feb,100),
			(item_set_slot,'itm_jodo_shinsu_charm',slot_item_mar,100),
			(item_set_slot,'itm_jodo_shinsu_charm',slot_item_apr,100),
			(item_set_slot,'itm_jodo_shinsu_charm',slot_item_may,100),
			(item_set_slot,'itm_jodo_shinsu_charm',slot_item_jun,100),
			(item_set_slot,'itm_jodo_shinsu_charm',slot_item_jul,100),
			(item_set_slot,'itm_jodo_shinsu_charm',slot_item_aug,100),
			(item_set_slot,'itm_jodo_shinsu_charm',slot_item_sep,100),
			(item_set_slot,'itm_jodo_shinsu_charm',slot_item_oct,100),
			(item_set_slot,'itm_jodo_shinsu_charm',slot_item_nov,100),
			(item_set_slot,'itm_jodo_shinsu_charm',slot_item_dec,100),
			(item_set_slot,'itm_jodo_shinsu_charm',slot_item_demand_coefficient,0),

			(item_set_slot,'itm_kojiki',slot_item_seaside,0),
			(item_set_slot,'itm_kojiki',slot_item_island,0),
			(item_set_slot,'itm_kojiki',slot_item_lakeside,0),
			(item_set_slot,'itm_kojiki',slot_item_lowland,0),
			(item_set_slot,'itm_kojiki',slot_item_highland,0),
			(item_set_slot,'itm_kojiki',slot_item_low_valley,0),
			(item_set_slot,'itm_kojiki',slot_item_high_valley,0),
			(item_set_slot,'itm_kojiki',slot_item_small_village,0),
			(item_set_slot,'itm_kojiki',slot_item_village,0),
			(item_set_slot,'itm_kojiki',slot_item_large_village,0),
			(item_set_slot,'itm_kojiki',slot_item_town,0),
			(item_set_slot,'itm_kojiki',slot_item_large_town,0),
			(item_set_slot,'itm_kojiki',slot_item_city,100),
			(item_set_slot,'itm_kojiki',slot_item_port,0),
			(item_set_slot,'itm_kojiki',slot_item_jan,100),
			(item_set_slot,'itm_kojiki',slot_item_feb,100),
			(item_set_slot,'itm_kojiki',slot_item_mar,100),
			(item_set_slot,'itm_kojiki',slot_item_apr,100),
			(item_set_slot,'itm_kojiki',slot_item_may,100),
			(item_set_slot,'itm_kojiki',slot_item_jun,100),
			(item_set_slot,'itm_kojiki',slot_item_jul,100),
			(item_set_slot,'itm_kojiki',slot_item_aug,100),
			(item_set_slot,'itm_kojiki',slot_item_sep,100),
			(item_set_slot,'itm_kojiki',slot_item_oct,100),
			(item_set_slot,'itm_kojiki',slot_item_nov,100),
			(item_set_slot,'itm_kojiki',slot_item_dec,100),
			(item_set_slot,'itm_kojiki',slot_item_demand_coefficient,0),

			(item_set_slot,'itm_koto',slot_item_seaside,0),
			(item_set_slot,'itm_koto',slot_item_island,0),
			(item_set_slot,'itm_koto',slot_item_lakeside,0),
			(item_set_slot,'itm_koto',slot_item_lowland,0),
			(item_set_slot,'itm_koto',slot_item_highland,0),
			(item_set_slot,'itm_koto',slot_item_low_valley,100),
			(item_set_slot,'itm_koto',slot_item_high_valley,100),
			(item_set_slot,'itm_koto',slot_item_small_village,0),
			(item_set_slot,'itm_koto',slot_item_village,0),
			(item_set_slot,'itm_koto',slot_item_large_village,0),
			(item_set_slot,'itm_koto',slot_item_town,0),
			(item_set_slot,'itm_koto',slot_item_large_town,0),
			(item_set_slot,'itm_koto',slot_item_city,100),
			(item_set_slot,'itm_koto',slot_item_port,0),
			(item_set_slot,'itm_koto',slot_item_jan,100),
			(item_set_slot,'itm_koto',slot_item_feb,100),
			(item_set_slot,'itm_koto',slot_item_mar,100),
			(item_set_slot,'itm_koto',slot_item_apr,100),
			(item_set_slot,'itm_koto',slot_item_may,100),
			(item_set_slot,'itm_koto',slot_item_jun,100),
			(item_set_slot,'itm_koto',slot_item_jul,100),
			(item_set_slot,'itm_koto',slot_item_aug,100),
			(item_set_slot,'itm_koto',slot_item_sep,100),
			(item_set_slot,'itm_koto',slot_item_oct,100),
			(item_set_slot,'itm_koto',slot_item_nov,100),
			(item_set_slot,'itm_koto',slot_item_dec,100),
			(item_set_slot,'itm_koto',slot_item_demand_coefficient,0),

			(item_set_slot,'itm_kuzu_root',slot_item_seaside,0),
			(item_set_slot,'itm_kuzu_root',slot_item_island,0),
			(item_set_slot,'itm_kuzu_root',slot_item_lakeside,0),
			(item_set_slot,'itm_kuzu_root',slot_item_lowland,200),
			(item_set_slot,'itm_kuzu_root',slot_item_highland,0),
			(item_set_slot,'itm_kuzu_root',slot_item_low_valley,0),
			(item_set_slot,'itm_kuzu_root',slot_item_high_valley,0),
			(item_set_slot,'itm_kuzu_root',slot_item_small_village,0),
			(item_set_slot,'itm_kuzu_root',slot_item_village,100),
			(item_set_slot,'itm_kuzu_root',slot_item_large_village,100),
			(item_set_slot,'itm_kuzu_root',slot_item_town,0),
			(item_set_slot,'itm_kuzu_root',slot_item_large_town,0),
			(item_set_slot,'itm_kuzu_root',slot_item_city,0),
			(item_set_slot,'itm_kuzu_root',slot_item_port,0),
			(item_set_slot,'itm_kuzu_root',slot_item_jan,100),
			(item_set_slot,'itm_kuzu_root',slot_item_feb,100),
			(item_set_slot,'itm_kuzu_root',slot_item_mar,100),
			(item_set_slot,'itm_kuzu_root',slot_item_apr,100),
			(item_set_slot,'itm_kuzu_root',slot_item_may,100),
			(item_set_slot,'itm_kuzu_root',slot_item_jun,100),
			(item_set_slot,'itm_kuzu_root',slot_item_jul,100),
			(item_set_slot,'itm_kuzu_root',slot_item_aug,100),
			(item_set_slot,'itm_kuzu_root',slot_item_sep,100),
			(item_set_slot,'itm_kuzu_root',slot_item_oct,100),
			(item_set_slot,'itm_kuzu_root',slot_item_nov,100),
			(item_set_slot,'itm_kuzu_root',slot_item_dec,100),
			(item_set_slot,'itm_kuzu_root',slot_item_demand_coefficient,0),

			(item_set_slot,'itm_kyoto_sake',slot_item_seaside,0),
			(item_set_slot,'itm_kyoto_sake',slot_item_island,0),
			(item_set_slot,'itm_kyoto_sake',slot_item_lakeside,0),
			(item_set_slot,'itm_kyoto_sake',slot_item_lowland,0),
			(item_set_slot,'itm_kyoto_sake',slot_item_highland,0),
			(item_set_slot,'itm_kyoto_sake',slot_item_low_valley,0),
			(item_set_slot,'itm_kyoto_sake',slot_item_high_valley,0),
			(item_set_slot,'itm_kyoto_sake',slot_item_small_village,0),
			(item_set_slot,'itm_kyoto_sake',slot_item_village,0),
			(item_set_slot,'itm_kyoto_sake',slot_item_large_village,0),
			(item_set_slot,'itm_kyoto_sake',slot_item_town,0),
			(item_set_slot,'itm_kyoto_sake',slot_item_large_town,0),
			(item_set_slot,'itm_kyoto_sake',slot_item_city,100),
			(item_set_slot,'itm_kyoto_sake',slot_item_port,0),
			(item_set_slot,'itm_kyoto_sake',slot_item_jan,100),
			(item_set_slot,'itm_kyoto_sake',slot_item_feb,100),
			(item_set_slot,'itm_kyoto_sake',slot_item_mar,100),
			(item_set_slot,'itm_kyoto_sake',slot_item_apr,100),
			(item_set_slot,'itm_kyoto_sake',slot_item_may,100),
			(item_set_slot,'itm_kyoto_sake',slot_item_jun,100),
			(item_set_slot,'itm_kyoto_sake',slot_item_jul,100),
			(item_set_slot,'itm_kyoto_sake',slot_item_aug,100),
			(item_set_slot,'itm_kyoto_sake',slot_item_sep,100),
			(item_set_slot,'itm_kyoto_sake',slot_item_oct,100),
			(item_set_slot,'itm_kyoto_sake',slot_item_nov,100),
			(item_set_slot,'itm_kyoto_sake',slot_item_dec,100),
			(item_set_slot,'itm_kyoto_sake',slot_item_demand_coefficient,0),

			(item_set_slot,'itm_lacquer',slot_item_seaside,0),
			(item_set_slot,'itm_lacquer',slot_item_island,0),
			(item_set_slot,'itm_lacquer',slot_item_lakeside,0),
			(item_set_slot,'itm_lacquer',slot_item_lowland,0),
			(item_set_slot,'itm_lacquer',slot_item_highland,100),
			(item_set_slot,'itm_lacquer',slot_item_low_valley,200),
			(item_set_slot,'itm_lacquer',slot_item_high_valley,200),
			(item_set_slot,'itm_lacquer',slot_item_small_village,0),
			(item_set_slot,'itm_lacquer',slot_item_village,0),
			(item_set_slot,'itm_lacquer',slot_item_large_village,0),
			(item_set_slot,'itm_lacquer',slot_item_town,0),
			(item_set_slot,'itm_lacquer',slot_item_large_town,0),
			(item_set_slot,'itm_lacquer',slot_item_city,0),
			(item_set_slot,'itm_lacquer',slot_item_port,0),
			(item_set_slot,'itm_lacquer',slot_item_jan,100),
			(item_set_slot,'itm_lacquer',slot_item_feb,100),
			(item_set_slot,'itm_lacquer',slot_item_mar,100),
			(item_set_slot,'itm_lacquer',slot_item_apr,100),
			(item_set_slot,'itm_lacquer',slot_item_may,100),
			(item_set_slot,'itm_lacquer',slot_item_jun,100),
			(item_set_slot,'itm_lacquer',slot_item_jul,100),
			(item_set_slot,'itm_lacquer',slot_item_aug,100),
			(item_set_slot,'itm_lacquer',slot_item_sep,100),
			(item_set_slot,'itm_lacquer',slot_item_oct,100),
			(item_set_slot,'itm_lacquer',slot_item_nov,100),
			(item_set_slot,'itm_lacquer',slot_item_dec,100),
			(item_set_slot,'itm_lacquer',slot_item_demand_coefficient,0),

			(item_set_slot,'itm_leather',slot_item_seaside,0),
			(item_set_slot,'itm_leather',slot_item_island,0),
			(item_set_slot,'itm_leather',slot_item_lakeside,0),
			(item_set_slot,'itm_leather',slot_item_lowland,100),
			(item_set_slot,'itm_leather',slot_item_highland,200),
			(item_set_slot,'itm_leather',slot_item_low_valley,100),
			(item_set_slot,'itm_leather',slot_item_high_valley,100),
			(item_set_slot,'itm_leather',slot_item_small_village,100),
			(item_set_slot,'itm_leather',slot_item_village,0),
			(item_set_slot,'itm_leather',slot_item_large_village,0),
			(item_set_slot,'itm_leather',slot_item_town,0),
			(item_set_slot,'itm_leather',slot_item_large_town,0),
			(item_set_slot,'itm_leather',slot_item_city,0),
			(item_set_slot,'itm_leather',slot_item_port,0),
			(item_set_slot,'itm_leather',slot_item_jan,100),
			(item_set_slot,'itm_leather',slot_item_feb,100),
			(item_set_slot,'itm_leather',slot_item_mar,100),
			(item_set_slot,'itm_leather',slot_item_apr,100),
			(item_set_slot,'itm_leather',slot_item_may,100),
			(item_set_slot,'itm_leather',slot_item_jun,100),
			(item_set_slot,'itm_leather',slot_item_jul,100),
			(item_set_slot,'itm_leather',slot_item_aug,100),
			(item_set_slot,'itm_leather',slot_item_sep,100),
			(item_set_slot,'itm_leather',slot_item_oct,100),
			(item_set_slot,'itm_leather',slot_item_nov,100),
			(item_set_slot,'itm_leather',slot_item_dec,100),
			(item_set_slot,'itm_leather',slot_item_demand_coefficient,0),

			(item_set_slot,'itm_linen',slot_item_seaside,0),
			(item_set_slot,'itm_linen',slot_item_island,0),
			(item_set_slot,'itm_linen',slot_item_lakeside,0),
			(item_set_slot,'itm_linen',slot_item_lowland,0),
			(item_set_slot,'itm_linen',slot_item_highland,0),
			(item_set_slot,'itm_linen',slot_item_low_valley,0),
			(item_set_slot,'itm_linen',slot_item_high_valley,0),
			(item_set_slot,'itm_linen',slot_item_small_village,0),
			(item_set_slot,'itm_linen',slot_item_village,0),
			(item_set_slot,'itm_linen',slot_item_large_village,100),
			(item_set_slot,'itm_linen',slot_item_town,100),
			(item_set_slot,'itm_linen',slot_item_large_town,100),
			(item_set_slot,'itm_linen',slot_item_city,200),
			(item_set_slot,'itm_linen',slot_item_port,0),
			(item_set_slot,'itm_linen',slot_item_jan,35),
			(item_set_slot,'itm_linen',slot_item_feb,25),
			(item_set_slot,'itm_linen',slot_item_mar,20),
			(item_set_slot,'itm_linen',slot_item_apr,15),
			(item_set_slot,'itm_linen',slot_item_may,10),
			(item_set_slot,'itm_linen',slot_item_jun,5),
			(item_set_slot,'itm_linen',slot_item_jul,100),
			(item_set_slot,'itm_linen',slot_item_aug,0),
			(item_set_slot,'itm_linen',slot_item_sep,100),
			(item_set_slot,'itm_linen',slot_item_oct,90),
			(item_set_slot,'itm_linen',slot_item_nov,75),
			(item_set_slot,'itm_linen',slot_item_dec,50),
			(item_set_slot,'itm_linen',slot_item_demand_coefficient,0),

			(item_set_slot,'itm_melons',slot_item_seaside,100),
			(item_set_slot,'itm_melons',slot_item_island,100),
			(item_set_slot,'itm_melons',slot_item_lakeside,100),
			(item_set_slot,'itm_melons',slot_item_lowland,200),
			(item_set_slot,'itm_melons',slot_item_highland,100),
			(item_set_slot,'itm_melons',slot_item_low_valley,100),
			(item_set_slot,'itm_melons',slot_item_high_valley,0),
			(item_set_slot,'itm_melons',slot_item_small_village,0),
			(item_set_slot,'itm_melons',slot_item_village,0),
			(item_set_slot,'itm_melons',slot_item_large_village,0),
			(item_set_slot,'itm_melons',slot_item_town,0),
			(item_set_slot,'itm_melons',slot_item_large_town,100),
			(item_set_slot,'itm_melons',slot_item_city,200),
			(item_set_slot,'itm_melons',slot_item_port,0),
			(item_set_slot,'itm_melons',slot_item_jan,0),
			(item_set_slot,'itm_melons',slot_item_feb,0),
			(item_set_slot,'itm_melons',slot_item_mar,0),
			(item_set_slot,'itm_melons',slot_item_apr,0),
			(item_set_slot,'itm_melons',slot_item_may,0),
			(item_set_slot,'itm_melons',slot_item_jun,100),
			(item_set_slot,'itm_melons',slot_item_jul,60),
			(item_set_slot,'itm_melons',slot_item_aug,30),
			(item_set_slot,'itm_melons',slot_item_sep,0),
			(item_set_slot,'itm_melons',slot_item_oct,0),
			(item_set_slot,'itm_melons',slot_item_nov,0),
			(item_set_slot,'itm_melons',slot_item_dec,0),
			(item_set_slot,'itm_melons',slot_item_demand_coefficient,0),

			(item_set_slot,'itm_metal_housewares',slot_item_seaside,0),
			(item_set_slot,'itm_metal_housewares',slot_item_island,0),
			(item_set_slot,'itm_metal_housewares',slot_item_lakeside,0),
			(item_set_slot,'itm_metal_housewares',slot_item_lowland,0),
			(item_set_slot,'itm_metal_housewares',slot_item_highland,0),
			(item_set_slot,'itm_metal_housewares',slot_item_low_valley,0),
			(item_set_slot,'itm_metal_housewares',slot_item_high_valley,0),
			(item_set_slot,'itm_metal_housewares',slot_item_small_village,0),
			(item_set_slot,'itm_metal_housewares',slot_item_village,0),
			(item_set_slot,'itm_metal_housewares',slot_item_large_village,0),
			(item_set_slot,'itm_metal_housewares',slot_item_town,0),
			(item_set_slot,'itm_metal_housewares',slot_item_large_town,100),
			(item_set_slot,'itm_metal_housewares',slot_item_city,200),
			(item_set_slot,'itm_metal_housewares',slot_item_port,0),
			(item_set_slot,'itm_metal_housewares',slot_item_jan,100),
			(item_set_slot,'itm_metal_housewares',slot_item_feb,100),
			(item_set_slot,'itm_metal_housewares',slot_item_mar,100),
			(item_set_slot,'itm_metal_housewares',slot_item_apr,100),
			(item_set_slot,'itm_metal_housewares',slot_item_may,100),
			(item_set_slot,'itm_metal_housewares',slot_item_jun,100),
			(item_set_slot,'itm_metal_housewares',slot_item_jul,100),
			(item_set_slot,'itm_metal_housewares',slot_item_aug,100),
			(item_set_slot,'itm_metal_housewares',slot_item_sep,100),
			(item_set_slot,'itm_metal_housewares',slot_item_oct,100),
			(item_set_slot,'itm_metal_housewares',slot_item_nov,100),
			(item_set_slot,'itm_metal_housewares',slot_item_dec,100),
			(item_set_slot,'itm_metal_housewares',slot_item_demand_coefficient,100),

			(item_set_slot,'itm_metal_tools',slot_item_seaside,0),
			(item_set_slot,'itm_metal_tools',slot_item_island,0),
			(item_set_slot,'itm_metal_tools',slot_item_lakeside,0),
			(item_set_slot,'itm_metal_tools',slot_item_lowland,0),
			(item_set_slot,'itm_metal_tools',slot_item_highland,0),
			(item_set_slot,'itm_metal_tools',slot_item_low_valley,0),
			(item_set_slot,'itm_metal_tools',slot_item_high_valley,0),
			(item_set_slot,'itm_metal_tools',slot_item_small_village,0),
			(item_set_slot,'itm_metal_tools',slot_item_village,0),
			(item_set_slot,'itm_metal_tools',slot_item_large_village,0),
			(item_set_slot,'itm_metal_tools',slot_item_town,0),
			(item_set_slot,'itm_metal_tools',slot_item_large_town,100),
			(item_set_slot,'itm_metal_tools',slot_item_city,200),
			(item_set_slot,'itm_metal_tools',slot_item_port,0),
			(item_set_slot,'itm_metal_tools',slot_item_jan,100),
			(item_set_slot,'itm_metal_tools',slot_item_feb,100),
			(item_set_slot,'itm_metal_tools',slot_item_mar,100),
			(item_set_slot,'itm_metal_tools',slot_item_apr,100),
			(item_set_slot,'itm_metal_tools',slot_item_may,100),
			(item_set_slot,'itm_metal_tools',slot_item_jun,100),
			(item_set_slot,'itm_metal_tools',slot_item_jul,100),
			(item_set_slot,'itm_metal_tools',slot_item_aug,100),
			(item_set_slot,'itm_metal_tools',slot_item_sep,100),
			(item_set_slot,'itm_metal_tools',slot_item_oct,100),
			(item_set_slot,'itm_metal_tools',slot_item_nov,100),
			(item_set_slot,'itm_metal_tools',slot_item_dec,100),
			(item_set_slot,'itm_metal_tools',slot_item_demand_coefficient,0),

			(item_set_slot,'itm_millet',slot_item_seaside,500),
			(item_set_slot,'itm_millet',slot_item_island,400),
			(item_set_slot,'itm_millet',slot_item_lakeside,500),
			(item_set_slot,'itm_millet',slot_item_lowland,600),
			(item_set_slot,'itm_millet',slot_item_highland,400),
			(item_set_slot,'itm_millet',slot_item_low_valley,300),
			(item_set_slot,'itm_millet',slot_item_high_valley,200),
			(item_set_slot,'itm_millet',slot_item_small_village,100),
			(item_set_slot,'itm_millet',slot_item_village,200),
			(item_set_slot,'itm_millet',slot_item_large_village,300),
			(item_set_slot,'itm_millet',slot_item_town,100),
			(item_set_slot,'itm_millet',slot_item_large_town,200),
			(item_set_slot,'itm_millet',slot_item_city,200),
			(item_set_slot,'itm_millet',slot_item_port,0),
			(item_set_slot,'itm_millet',slot_item_jan,15),
			(item_set_slot,'itm_millet',slot_item_feb,10),
			(item_set_slot,'itm_millet',slot_item_mar,5),
			(item_set_slot,'itm_millet',slot_item_apr,0),
			(item_set_slot,'itm_millet',slot_item_may,0),
			(item_set_slot,'itm_millet',slot_item_jun,100),
			(item_set_slot,'itm_millet',slot_item_jul,90),
			(item_set_slot,'itm_millet',slot_item_aug,75),
			(item_set_slot,'itm_millet',slot_item_sep,50),
			(item_set_slot,'itm_millet',slot_item_oct,35),
			(item_set_slot,'itm_millet',slot_item_nov,25),
			(item_set_slot,'itm_millet',slot_item_dec,20),
			(item_set_slot,'itm_millet',slot_item_demand_coefficient,1000),

			(item_set_slot,'itm_mirror',slot_item_seaside,0),
			(item_set_slot,'itm_mirror',slot_item_island,0),
			(item_set_slot,'itm_mirror',slot_item_lakeside,0),
			(item_set_slot,'itm_mirror',slot_item_lowland,0),
			(item_set_slot,'itm_mirror',slot_item_highland,0),
			(item_set_slot,'itm_mirror',slot_item_low_valley,0),
			(item_set_slot,'itm_mirror',slot_item_high_valley,0),
			(item_set_slot,'itm_mirror',slot_item_small_village,0),
			(item_set_slot,'itm_mirror',slot_item_village,0),
			(item_set_slot,'itm_mirror',slot_item_large_village,0),
			(item_set_slot,'itm_mirror',slot_item_town,0),
			(item_set_slot,'itm_mirror',slot_item_large_town,0),
			(item_set_slot,'itm_mirror',slot_item_city,100),
			(item_set_slot,'itm_mirror',slot_item_port,0),
			(item_set_slot,'itm_mirror',slot_item_jan,100),
			(item_set_slot,'itm_mirror',slot_item_feb,100),
			(item_set_slot,'itm_mirror',slot_item_mar,100),
			(item_set_slot,'itm_mirror',slot_item_apr,100),
			(item_set_slot,'itm_mirror',slot_item_may,100),
			(item_set_slot,'itm_mirror',slot_item_jun,100),
			(item_set_slot,'itm_mirror',slot_item_jul,100),
			(item_set_slot,'itm_mirror',slot_item_aug,100),
			(item_set_slot,'itm_mirror',slot_item_sep,100),
			(item_set_slot,'itm_mirror',slot_item_oct,100),
			(item_set_slot,'itm_mirror',slot_item_nov,100),
			(item_set_slot,'itm_mirror',slot_item_dec,100),
			(item_set_slot,'itm_mirror',slot_item_demand_coefficient,0),

			(item_set_slot,'itm_mushrooms',slot_item_seaside,0),
			(item_set_slot,'itm_mushrooms',slot_item_island,0),
			(item_set_slot,'itm_mushrooms',slot_item_lakeside,0),
			(item_set_slot,'itm_mushrooms',slot_item_lowland,0),
			(item_set_slot,'itm_mushrooms',slot_item_highland,200),
			(item_set_slot,'itm_mushrooms',slot_item_low_valley,100),
			(item_set_slot,'itm_mushrooms',slot_item_high_valley,200),
			(item_set_slot,'itm_mushrooms',slot_item_small_village,0),
			(item_set_slot,'itm_mushrooms',slot_item_village,0),
			(item_set_slot,'itm_mushrooms',slot_item_large_village,100),
			(item_set_slot,'itm_mushrooms',slot_item_town,100),
			(item_set_slot,'itm_mushrooms',slot_item_large_town,0),
			(item_set_slot,'itm_mushrooms',slot_item_city,0),
			(item_set_slot,'itm_mushrooms',slot_item_port,0),
			(item_set_slot,'itm_mushrooms',slot_item_jan,100),
			(item_set_slot,'itm_mushrooms',slot_item_feb,100),
			(item_set_slot,'itm_mushrooms',slot_item_mar,100),
			(item_set_slot,'itm_mushrooms',slot_item_apr,100),
			(item_set_slot,'itm_mushrooms',slot_item_may,100),
			(item_set_slot,'itm_mushrooms',slot_item_jun,100),
			(item_set_slot,'itm_mushrooms',slot_item_jul,100),
			(item_set_slot,'itm_mushrooms',slot_item_aug,100),
			(item_set_slot,'itm_mushrooms',slot_item_sep,100),
			(item_set_slot,'itm_mushrooms',slot_item_oct,100),
			(item_set_slot,'itm_mushrooms',slot_item_nov,100),
			(item_set_slot,'itm_mushrooms',slot_item_dec,100),
			(item_set_slot,'itm_mushrooms',slot_item_demand_coefficient,0),

			(item_set_slot,'itm_oil',slot_item_seaside,100),
			(item_set_slot,'itm_oil',slot_item_island,0),
			(item_set_slot,'itm_oil',slot_item_lakeside,100),
			(item_set_slot,'itm_oil',slot_item_lowland,200),
			(item_set_slot,'itm_oil',slot_item_highland,100),
			(item_set_slot,'itm_oil',slot_item_low_valley,100),
			(item_set_slot,'itm_oil',slot_item_high_valley,0),
			(item_set_slot,'itm_oil',slot_item_small_village,100),
			(item_set_slot,'itm_oil',slot_item_village,100),
			(item_set_slot,'itm_oil',slot_item_large_village,100),
			(item_set_slot,'itm_oil',slot_item_town,0),
			(item_set_slot,'itm_oil',slot_item_large_town,0),
			(item_set_slot,'itm_oil',slot_item_city,0),
			(item_set_slot,'itm_oil',slot_item_port,0),
			(item_set_slot,'itm_oil',slot_item_jan,100),
			(item_set_slot,'itm_oil',slot_item_feb,100),
			(item_set_slot,'itm_oil',slot_item_mar,100),
			(item_set_slot,'itm_oil',slot_item_apr,100),
			(item_set_slot,'itm_oil',slot_item_may,100),
			(item_set_slot,'itm_oil',slot_item_jun,100),
			(item_set_slot,'itm_oil',slot_item_jul,100),
			(item_set_slot,'itm_oil',slot_item_aug,100),
			(item_set_slot,'itm_oil',slot_item_sep,100),
			(item_set_slot,'itm_oil',slot_item_oct,100),
			(item_set_slot,'itm_oil',slot_item_nov,100),
			(item_set_slot,'itm_oil',slot_item_dec,100),
			(item_set_slot,'itm_oil',slot_item_demand_coefficient,0),

			(item_set_slot,'itm_otogizoushi',slot_item_seaside,0),
			(item_set_slot,'itm_otogizoushi',slot_item_island,0),
			(item_set_slot,'itm_otogizoushi',slot_item_lakeside,0),
			(item_set_slot,'itm_otogizoushi',slot_item_lowland,0),
			(item_set_slot,'itm_otogizoushi',slot_item_highland,0),
			(item_set_slot,'itm_otogizoushi',slot_item_low_valley,0),
			(item_set_slot,'itm_otogizoushi',slot_item_high_valley,0),
			(item_set_slot,'itm_otogizoushi',slot_item_small_village,0),
			(item_set_slot,'itm_otogizoushi',slot_item_village,0),
			(item_set_slot,'itm_otogizoushi',slot_item_large_village,0),
			(item_set_slot,'itm_otogizoushi',slot_item_town,0),
			(item_set_slot,'itm_otogizoushi',slot_item_large_town,100),
			(item_set_slot,'itm_otogizoushi',slot_item_city,200),
			(item_set_slot,'itm_otogizoushi',slot_item_port,0),
			(item_set_slot,'itm_otogizoushi',slot_item_jan,100),
			(item_set_slot,'itm_otogizoushi',slot_item_feb,100),
			(item_set_slot,'itm_otogizoushi',slot_item_mar,100),
			(item_set_slot,'itm_otogizoushi',slot_item_apr,100),
			(item_set_slot,'itm_otogizoushi',slot_item_may,100),
			(item_set_slot,'itm_otogizoushi',slot_item_jun,100),
			(item_set_slot,'itm_otogizoushi',slot_item_jul,100),
			(item_set_slot,'itm_otogizoushi',slot_item_aug,100),
			(item_set_slot,'itm_otogizoushi',slot_item_sep,100),
			(item_set_slot,'itm_otogizoushi',slot_item_oct,100),
			(item_set_slot,'itm_otogizoushi',slot_item_nov,100),
			(item_set_slot,'itm_otogizoushi',slot_item_dec,100),
			(item_set_slot,'itm_otogizoushi',slot_item_demand_coefficient,0),

			(item_set_slot,'itm_paper',slot_item_seaside,0),
			(item_set_slot,'itm_paper',slot_item_island,0),
			(item_set_slot,'itm_paper',slot_item_lakeside,0),
			(item_set_slot,'itm_paper',slot_item_lowland,0),
			(item_set_slot,'itm_paper',slot_item_highland,300),
			(item_set_slot,'itm_paper',slot_item_low_valley,200),
			(item_set_slot,'itm_paper',slot_item_high_valley,100),
			(item_set_slot,'itm_paper',slot_item_small_village,0),
			(item_set_slot,'itm_paper',slot_item_village,100),
			(item_set_slot,'itm_paper',slot_item_large_village,200),
			(item_set_slot,'itm_paper',slot_item_town,0),
			(item_set_slot,'itm_paper',slot_item_large_town,0),
			(item_set_slot,'itm_paper',slot_item_city,0),
			(item_set_slot,'itm_paper',slot_item_port,0),
			(item_set_slot,'itm_paper',slot_item_jan,80),
			(item_set_slot,'itm_paper',slot_item_feb,60),
			(item_set_slot,'itm_paper',slot_item_mar,30),
			(item_set_slot,'itm_paper',slot_item_apr,20),
			(item_set_slot,'itm_paper',slot_item_may,20),
			(item_set_slot,'itm_paper',slot_item_jun,20),
			(item_set_slot,'itm_paper',slot_item_jul,20),
			(item_set_slot,'itm_paper',slot_item_aug,20),
			(item_set_slot,'itm_paper',slot_item_sep,20),
			(item_set_slot,'itm_paper',slot_item_oct,100),
			(item_set_slot,'itm_paper',slot_item_nov,100),
			(item_set_slot,'itm_paper',slot_item_dec,100),
			(item_set_slot,'itm_paper',slot_item_demand_coefficient,50),

			(item_set_slot,'itm_peaches',slot_item_seaside,0),
			(item_set_slot,'itm_peaches',slot_item_island,0),
			(item_set_slot,'itm_peaches',slot_item_lakeside,0),
			(item_set_slot,'itm_peaches',slot_item_lowland,100),
			(item_set_slot,'itm_peaches',slot_item_highland,200),
			(item_set_slot,'itm_peaches',slot_item_low_valley,100),
			(item_set_slot,'itm_peaches',slot_item_high_valley,100),
			(item_set_slot,'itm_peaches',slot_item_small_village,0),
			(item_set_slot,'itm_peaches',slot_item_village,0),
			(item_set_slot,'itm_peaches',slot_item_large_village,0),
			(item_set_slot,'itm_peaches',slot_item_town,0),
			(item_set_slot,'itm_peaches',slot_item_large_town,100),
			(item_set_slot,'itm_peaches',slot_item_city,200),
			(item_set_slot,'itm_peaches',slot_item_port,0),
			(item_set_slot,'itm_peaches',slot_item_jan,0),
			(item_set_slot,'itm_peaches',slot_item_feb,0),
			(item_set_slot,'itm_peaches',slot_item_mar,0),
			(item_set_slot,'itm_peaches',slot_item_apr,0),
			(item_set_slot,'itm_peaches',slot_item_may,0),
			(item_set_slot,'itm_peaches',slot_item_jun,0),
			(item_set_slot,'itm_peaches',slot_item_jul,100),
			(item_set_slot,'itm_peaches',slot_item_aug,80),
			(item_set_slot,'itm_peaches',slot_item_sep,30),
			(item_set_slot,'itm_peaches',slot_item_oct,0),
			(item_set_slot,'itm_peaches',slot_item_nov,0),
			(item_set_slot,'itm_peaches',slot_item_dec,0),
			(item_set_slot,'itm_peaches',slot_item_demand_coefficient,0),

			(item_set_slot,'itm_persimmons',slot_item_seaside,0),
			(item_set_slot,'itm_persimmons',slot_item_island,0),
			(item_set_slot,'itm_persimmons',slot_item_lakeside,0),
			(item_set_slot,'itm_persimmons',slot_item_lowland,100),
			(item_set_slot,'itm_persimmons',slot_item_highland,200),
			(item_set_slot,'itm_persimmons',slot_item_low_valley,100),
			(item_set_slot,'itm_persimmons',slot_item_high_valley,100),
			(item_set_slot,'itm_persimmons',slot_item_small_village,0),
			(item_set_slot,'itm_persimmons',slot_item_village,0),
			(item_set_slot,'itm_persimmons',slot_item_large_village,0),
			(item_set_slot,'itm_persimmons',slot_item_town,0),
			(item_set_slot,'itm_persimmons',slot_item_large_town,100),
			(item_set_slot,'itm_persimmons',slot_item_city,200),
			(item_set_slot,'itm_persimmons',slot_item_port,0),
			(item_set_slot,'itm_persimmons',slot_item_jan,35),
			(item_set_slot,'itm_persimmons',slot_item_feb,25),
			(item_set_slot,'itm_persimmons',slot_item_mar,20),
			(item_set_slot,'itm_persimmons',slot_item_apr,15),
			(item_set_slot,'itm_persimmons',slot_item_may,10),
			(item_set_slot,'itm_persimmons',slot_item_jun,5),
			(item_set_slot,'itm_persimmons',slot_item_jul,0),
			(item_set_slot,'itm_persimmons',slot_item_aug,0),
			(item_set_slot,'itm_persimmons',slot_item_sep,100),
			(item_set_slot,'itm_persimmons',slot_item_oct,90),
			(item_set_slot,'itm_persimmons',slot_item_nov,75),
			(item_set_slot,'itm_persimmons',slot_item_dec,50),
			(item_set_slot,'itm_persimmons',slot_item_demand_coefficient,0),

			(item_set_slot,'itm_picture_books',slot_item_seaside,0),
			(item_set_slot,'itm_picture_books',slot_item_island,0),
			(item_set_slot,'itm_picture_books',slot_item_lakeside,0),
			(item_set_slot,'itm_picture_books',slot_item_lowland,0),
			(item_set_slot,'itm_picture_books',slot_item_highland,0),
			(item_set_slot,'itm_picture_books',slot_item_low_valley,0),
			(item_set_slot,'itm_picture_books',slot_item_high_valley,0),
			(item_set_slot,'itm_picture_books',slot_item_small_village,0),
			(item_set_slot,'itm_picture_books',slot_item_village,0),
			(item_set_slot,'itm_picture_books',slot_item_large_village,0),
			(item_set_slot,'itm_picture_books',slot_item_town,0),
			(item_set_slot,'itm_picture_books',slot_item_large_town,100),
			(item_set_slot,'itm_picture_books',slot_item_city,200),
			(item_set_slot,'itm_picture_books',slot_item_port,0),
			(item_set_slot,'itm_picture_books',slot_item_jan,100),
			(item_set_slot,'itm_picture_books',slot_item_feb,100),
			(item_set_slot,'itm_picture_books',slot_item_mar,100),
			(item_set_slot,'itm_picture_books',slot_item_apr,100),
			(item_set_slot,'itm_picture_books',slot_item_may,100),
			(item_set_slot,'itm_picture_books',slot_item_jun,100),
			(item_set_slot,'itm_picture_books',slot_item_jul,100),
			(item_set_slot,'itm_picture_books',slot_item_aug,100),
			(item_set_slot,'itm_picture_books',slot_item_sep,100),
			(item_set_slot,'itm_picture_books',slot_item_oct,100),
			(item_set_slot,'itm_picture_books',slot_item_nov,100),
			(item_set_slot,'itm_picture_books',slot_item_dec,100),
			(item_set_slot,'itm_picture_books',slot_item_demand_coefficient,0),

			(item_set_slot,'itm_poetry_books',slot_item_seaside,0),
			(item_set_slot,'itm_poetry_books',slot_item_island,0),
			(item_set_slot,'itm_poetry_books',slot_item_lakeside,0),
			(item_set_slot,'itm_poetry_books',slot_item_lowland,0),
			(item_set_slot,'itm_poetry_books',slot_item_highland,0),
			(item_set_slot,'itm_poetry_books',slot_item_low_valley,0),
			(item_set_slot,'itm_poetry_books',slot_item_high_valley,0),
			(item_set_slot,'itm_poetry_books',slot_item_small_village,0),
			(item_set_slot,'itm_poetry_books',slot_item_village,0),
			(item_set_slot,'itm_poetry_books',slot_item_large_village,0),
			(item_set_slot,'itm_poetry_books',slot_item_town,0),
			(item_set_slot,'itm_poetry_books',slot_item_large_town,100),
			(item_set_slot,'itm_poetry_books',slot_item_city,200),
			(item_set_slot,'itm_poetry_books',slot_item_port,0),
			(item_set_slot,'itm_poetry_books',slot_item_jan,100),
			(item_set_slot,'itm_poetry_books',slot_item_feb,100),
			(item_set_slot,'itm_poetry_books',slot_item_mar,100),
			(item_set_slot,'itm_poetry_books',slot_item_apr,100),
			(item_set_slot,'itm_poetry_books',slot_item_may,100),
			(item_set_slot,'itm_poetry_books',slot_item_jun,100),
			(item_set_slot,'itm_poetry_books',slot_item_jul,100),
			(item_set_slot,'itm_poetry_books',slot_item_aug,100),
			(item_set_slot,'itm_poetry_books',slot_item_sep,100),
			(item_set_slot,'itm_poetry_books',slot_item_oct,100),
			(item_set_slot,'itm_poetry_books',slot_item_nov,100),
			(item_set_slot,'itm_poetry_books',slot_item_dec,100),
			(item_set_slot,'itm_poetry_books',slot_item_demand_coefficient,0),

			(item_set_slot,'itm_pottery',slot_item_seaside,100),
			(item_set_slot,'itm_pottery',slot_item_island,100),
			(item_set_slot,'itm_pottery',slot_item_lakeside,200),
			(item_set_slot,'itm_pottery',slot_item_lowland,200),
			(item_set_slot,'itm_pottery',slot_item_highland,200),
			(item_set_slot,'itm_pottery',slot_item_low_valley,100),
			(item_set_slot,'itm_pottery',slot_item_high_valley,100),
			(item_set_slot,'itm_pottery',slot_item_small_village,0),
			(item_set_slot,'itm_pottery',slot_item_village,0),
			(item_set_slot,'itm_pottery',slot_item_large_village,100),
			(item_set_slot,'itm_pottery',slot_item_town,100),
			(item_set_slot,'itm_pottery',slot_item_large_town,200),
			(item_set_slot,'itm_pottery',slot_item_city,200),
			(item_set_slot,'itm_pottery',slot_item_port,0),
			(item_set_slot,'itm_pottery',slot_item_jan,100),
			(item_set_slot,'itm_pottery',slot_item_feb,100),
			(item_set_slot,'itm_pottery',slot_item_mar,100),
			(item_set_slot,'itm_pottery',slot_item_apr,100),
			(item_set_slot,'itm_pottery',slot_item_may,100),
			(item_set_slot,'itm_pottery',slot_item_jun,100),
			(item_set_slot,'itm_pottery',slot_item_jul,100),
			(item_set_slot,'itm_pottery',slot_item_aug,100),
			(item_set_slot,'itm_pottery',slot_item_sep,100),
			(item_set_slot,'itm_pottery',slot_item_oct,100),
			(item_set_slot,'itm_pottery',slot_item_nov,100),
			(item_set_slot,'itm_pottery',slot_item_dec,100),
			(item_set_slot,'itm_pottery',slot_item_demand_coefficient,0),

			(item_set_slot,'itm_raincoats',slot_item_seaside,0),
			(item_set_slot,'itm_raincoats',slot_item_island,0),
			(item_set_slot,'itm_raincoats',slot_item_lakeside,100),
			(item_set_slot,'itm_raincoats',slot_item_lowland,100),
			(item_set_slot,'itm_raincoats',slot_item_highland,100),
			(item_set_slot,'itm_raincoats',slot_item_low_valley,100),
			(item_set_slot,'itm_raincoats',slot_item_high_valley,100),
			(item_set_slot,'itm_raincoats',slot_item_small_village,0),
			(item_set_slot,'itm_raincoats',slot_item_village,0),
			(item_set_slot,'itm_raincoats',slot_item_large_village,100),
			(item_set_slot,'itm_raincoats',slot_item_town,0),
			(item_set_slot,'itm_raincoats',slot_item_large_town,0),
			(item_set_slot,'itm_raincoats',slot_item_city,0),
			(item_set_slot,'itm_raincoats',slot_item_port,0),
			(item_set_slot,'itm_raincoats',slot_item_jan,80),
			(item_set_slot,'itm_raincoats',slot_item_feb,60),
			(item_set_slot,'itm_raincoats',slot_item_mar,20),
			(item_set_slot,'itm_raincoats',slot_item_apr,20),
			(item_set_slot,'itm_raincoats',slot_item_may,20),
			(item_set_slot,'itm_raincoats',slot_item_jun,20),
			(item_set_slot,'itm_raincoats',slot_item_jul,20),
			(item_set_slot,'itm_raincoats',slot_item_aug,20),
			(item_set_slot,'itm_raincoats',slot_item_sep,20),
			(item_set_slot,'itm_raincoats',slot_item_oct,100),
			(item_set_slot,'itm_raincoats',slot_item_nov,100),
			(item_set_slot,'itm_raincoats',slot_item_dec,100),
			(item_set_slot,'itm_raincoats',slot_item_demand_coefficient,0),

			(item_set_slot,'itm_rice',slot_item_seaside,900),
			(item_set_slot,'itm_rice',slot_item_island,800),
			(item_set_slot,'itm_rice',slot_item_lakeside,900),
			(item_set_slot,'itm_rice',slot_item_lowland,1000),
			(item_set_slot,'itm_rice',slot_item_highland,800),
			(item_set_slot,'itm_rice',slot_item_low_valley,600),
			(item_set_slot,'itm_rice',slot_item_high_valley,400),
			(item_set_slot,'itm_rice',slot_item_small_village,0),
			(item_set_slot,'itm_rice',slot_item_village,100),
			(item_set_slot,'itm_rice',slot_item_large_village,300),
			(item_set_slot,'itm_rice',slot_item_town,300),
			(item_set_slot,'itm_rice',slot_item_large_town,200),
			(item_set_slot,'itm_rice',slot_item_city,100),
			(item_set_slot,'itm_rice',slot_item_port,0),
			(item_set_slot,'itm_rice',slot_item_jan,35),
			(item_set_slot,'itm_rice',slot_item_feb,25),
			(item_set_slot,'itm_rice',slot_item_mar,20),
			(item_set_slot,'itm_rice',slot_item_apr,15),
			(item_set_slot,'itm_rice',slot_item_may,10),
			(item_set_slot,'itm_rice',slot_item_jun,5),
			(item_set_slot,'itm_rice',slot_item_jul,0),
			(item_set_slot,'itm_rice',slot_item_aug,0),
			(item_set_slot,'itm_rice',slot_item_sep,100),
			(item_set_slot,'itm_rice',slot_item_oct,90),
			(item_set_slot,'itm_rice',slot_item_nov,75),
			(item_set_slot,'itm_rice',slot_item_dec,50),
			(item_set_slot,'itm_rice',slot_item_demand_coefficient,0),

			(item_set_slot,'itm_sake',slot_item_seaside,0),
			(item_set_slot,'itm_sake',slot_item_island,0),
			(item_set_slot,'itm_sake',slot_item_lakeside,0),
			(item_set_slot,'itm_sake',slot_item_lowland,0),
			(item_set_slot,'itm_sake',slot_item_highland,0),
			(item_set_slot,'itm_sake',slot_item_low_valley,0),
			(item_set_slot,'itm_sake',slot_item_high_valley,0),
			(item_set_slot,'itm_sake',slot_item_small_village,0),
			(item_set_slot,'itm_sake',slot_item_village,0),
			(item_set_slot,'itm_sake',slot_item_large_village,0),
			(item_set_slot,'itm_sake',slot_item_town,200),
			(item_set_slot,'itm_sake',slot_item_large_town,300),
			(item_set_slot,'itm_sake',slot_item_city,400),
			(item_set_slot,'itm_sake',slot_item_port,0),
			(item_set_slot,'itm_sake',slot_item_jan,100),
			(item_set_slot,'itm_sake',slot_item_feb,100),
			(item_set_slot,'itm_sake',slot_item_mar,100),
			(item_set_slot,'itm_sake',slot_item_apr,100),
			(item_set_slot,'itm_sake',slot_item_may,100),
			(item_set_slot,'itm_sake',slot_item_jun,100),
			(item_set_slot,'itm_sake',slot_item_jul,100),
			(item_set_slot,'itm_sake',slot_item_aug,100),
			(item_set_slot,'itm_sake',slot_item_sep,100),
			(item_set_slot,'itm_sake',slot_item_oct,100),
			(item_set_slot,'itm_sake',slot_item_nov,100),
			(item_set_slot,'itm_sake',slot_item_dec,100),
			(item_set_slot,'itm_sake',slot_item_demand_coefficient,500),

			(item_set_slot,'itm_salt',slot_item_seaside,400),
			(item_set_slot,'itm_salt',slot_item_island,200),
			(item_set_slot,'itm_salt',slot_item_lakeside,0),
			(item_set_slot,'itm_salt',slot_item_lowland,0),
			(item_set_slot,'itm_salt',slot_item_highland,0),
			(item_set_slot,'itm_salt',slot_item_low_valley,0),
			(item_set_slot,'itm_salt',slot_item_high_valley,0),
			(item_set_slot,'itm_salt',slot_item_small_village,0),
			(item_set_slot,'itm_salt',slot_item_village,0),
			(item_set_slot,'itm_salt',slot_item_large_village,0),
			(item_set_slot,'itm_salt',slot_item_town,0),
			(item_set_slot,'itm_salt',slot_item_large_town,0),
			(item_set_slot,'itm_salt',slot_item_city,0),
			(item_set_slot,'itm_salt',slot_item_port,0),
			(item_set_slot,'itm_salt',slot_item_jan,100),
			(item_set_slot,'itm_salt',slot_item_feb,100),
			(item_set_slot,'itm_salt',slot_item_mar,100),
			(item_set_slot,'itm_salt',slot_item_apr,100),
			(item_set_slot,'itm_salt',slot_item_may,100),
			(item_set_slot,'itm_salt',slot_item_jun,100),
			(item_set_slot,'itm_salt',slot_item_jul,100),
			(item_set_slot,'itm_salt',slot_item_aug,100),
			(item_set_slot,'itm_salt',slot_item_sep,100),
			(item_set_slot,'itm_salt',slot_item_oct,100),
			(item_set_slot,'itm_salt',slot_item_nov,100),
			(item_set_slot,'itm_salt',slot_item_dec,100),
			(item_set_slot,'itm_salt',slot_item_demand_coefficient,0),

			(item_set_slot,'itm_salted_fish',slot_item_seaside,800),
			(item_set_slot,'itm_salted_fish',slot_item_island,800),
			(item_set_slot,'itm_salted_fish',slot_item_lakeside,700),
			(item_set_slot,'itm_salted_fish',slot_item_lowland,300),
			(item_set_slot,'itm_salted_fish',slot_item_highland,200),
			(item_set_slot,'itm_salted_fish',slot_item_low_valley,100),
			(item_set_slot,'itm_salted_fish',slot_item_high_valley,0),
			(item_set_slot,'itm_salted_fish',slot_item_small_village,0),
			(item_set_slot,'itm_salted_fish',slot_item_village,0),
			(item_set_slot,'itm_salted_fish',slot_item_large_village,0),
			(item_set_slot,'itm_salted_fish',slot_item_town,0),
			(item_set_slot,'itm_salted_fish',slot_item_large_town,100),
			(item_set_slot,'itm_salted_fish',slot_item_city,200),
			(item_set_slot,'itm_salted_fish',slot_item_port,0),
			(item_set_slot,'itm_salted_fish',slot_item_jan,100),
			(item_set_slot,'itm_salted_fish',slot_item_feb,100),
			(item_set_slot,'itm_salted_fish',slot_item_mar,100),
			(item_set_slot,'itm_salted_fish',slot_item_apr,100),
			(item_set_slot,'itm_salted_fish',slot_item_may,100),
			(item_set_slot,'itm_salted_fish',slot_item_jun,100),
			(item_set_slot,'itm_salted_fish',slot_item_jul,100),
			(item_set_slot,'itm_salted_fish',slot_item_aug,100),
			(item_set_slot,'itm_salted_fish',slot_item_sep,100),
			(item_set_slot,'itm_salted_fish',slot_item_oct,100),
			(item_set_slot,'itm_salted_fish',slot_item_nov,100),
			(item_set_slot,'itm_salted_fish',slot_item_dec,100),
			(item_set_slot,'itm_salted_fish',slot_item_demand_coefficient,0),

			(item_set_slot,'itm_sandals',slot_item_seaside,0),
			(item_set_slot,'itm_sandals',slot_item_island,0),
			(item_set_slot,'itm_sandals',slot_item_lakeside,100),
			(item_set_slot,'itm_sandals',slot_item_lowland,100),
			(item_set_slot,'itm_sandals',slot_item_highland,100),
			(item_set_slot,'itm_sandals',slot_item_low_valley,100),
			(item_set_slot,'itm_sandals',slot_item_high_valley,100),
			(item_set_slot,'itm_sandals',slot_item_small_village,0),
			(item_set_slot,'itm_sandals',slot_item_village,0),
			(item_set_slot,'itm_sandals',slot_item_large_village,100),
			(item_set_slot,'itm_sandals',slot_item_town,0),
			(item_set_slot,'itm_sandals',slot_item_large_town,0),
			(item_set_slot,'itm_sandals',slot_item_city,0),
			(item_set_slot,'itm_sandals',slot_item_port,0),
			(item_set_slot,'itm_sandals',slot_item_jan,80),
			(item_set_slot,'itm_sandals',slot_item_feb,60),
			(item_set_slot,'itm_sandals',slot_item_mar,20),
			(item_set_slot,'itm_sandals',slot_item_apr,20),
			(item_set_slot,'itm_sandals',slot_item_may,20),
			(item_set_slot,'itm_sandals',slot_item_jun,20),
			(item_set_slot,'itm_sandals',slot_item_jul,20),
			(item_set_slot,'itm_sandals',slot_item_aug,20),
			(item_set_slot,'itm_sandals',slot_item_sep,20),
			(item_set_slot,'itm_sandals',slot_item_oct,100),
			(item_set_slot,'itm_sandals',slot_item_nov,100),
			(item_set_slot,'itm_sandals',slot_item_dec,100),
			(item_set_slot,'itm_sandals',slot_item_demand_coefficient,0),

			(item_set_slot,'itm_sculptures',slot_item_seaside,0),
			(item_set_slot,'itm_sculptures',slot_item_island,0),
			(item_set_slot,'itm_sculptures',slot_item_lakeside,0),
			(item_set_slot,'itm_sculptures',slot_item_lowland,0),
			(item_set_slot,'itm_sculptures',slot_item_highland,0),
			(item_set_slot,'itm_sculptures',slot_item_low_valley,0),
			(item_set_slot,'itm_sculptures',slot_item_high_valley,100),
			(item_set_slot,'itm_sculptures',slot_item_small_village,0),
			(item_set_slot,'itm_sculptures',slot_item_village,0),
			(item_set_slot,'itm_sculptures',slot_item_large_village,0),
			(item_set_slot,'itm_sculptures',slot_item_town,0),
			(item_set_slot,'itm_sculptures',slot_item_large_town,0),
			(item_set_slot,'itm_sculptures',slot_item_city,100),
			(item_set_slot,'itm_sculptures',slot_item_port,0),
			(item_set_slot,'itm_sculptures',slot_item_jan,100),
			(item_set_slot,'itm_sculptures',slot_item_feb,100),
			(item_set_slot,'itm_sculptures',slot_item_mar,100),
			(item_set_slot,'itm_sculptures',slot_item_apr,100),
			(item_set_slot,'itm_sculptures',slot_item_may,100),
			(item_set_slot,'itm_sculptures',slot_item_jun,100),
			(item_set_slot,'itm_sculptures',slot_item_jul,100),
			(item_set_slot,'itm_sculptures',slot_item_aug,100),
			(item_set_slot,'itm_sculptures',slot_item_sep,100),
			(item_set_slot,'itm_sculptures',slot_item_oct,100),
			(item_set_slot,'itm_sculptures',slot_item_nov,100),
			(item_set_slot,'itm_sculptures',slot_item_dec,100),
			(item_set_slot,'itm_sculptures',slot_item_demand_coefficient,0),

			(item_set_slot,'itm_sesshu_painting',slot_item_seaside,0),
			(item_set_slot,'itm_sesshu_painting',slot_item_island,0),
			(item_set_slot,'itm_sesshu_painting',slot_item_lakeside,0),
			(item_set_slot,'itm_sesshu_painting',slot_item_lowland,0),
			(item_set_slot,'itm_sesshu_painting',slot_item_highland,0),
			(item_set_slot,'itm_sesshu_painting',slot_item_low_valley,0),
			(item_set_slot,'itm_sesshu_painting',slot_item_high_valley,0),
			(item_set_slot,'itm_sesshu_painting',slot_item_small_village,0),
			(item_set_slot,'itm_sesshu_painting',slot_item_village,0),
			(item_set_slot,'itm_sesshu_painting',slot_item_large_village,0),
			(item_set_slot,'itm_sesshu_painting',slot_item_town,0),
			(item_set_slot,'itm_sesshu_painting',slot_item_large_town,100),
			(item_set_slot,'itm_sesshu_painting',slot_item_city,200),
			(item_set_slot,'itm_sesshu_painting',slot_item_port,0),
			(item_set_slot,'itm_sesshu_painting',slot_item_jan,100),
			(item_set_slot,'itm_sesshu_painting',slot_item_feb,100),
			(item_set_slot,'itm_sesshu_painting',slot_item_mar,100),
			(item_set_slot,'itm_sesshu_painting',slot_item_apr,100),
			(item_set_slot,'itm_sesshu_painting',slot_item_may,100),
			(item_set_slot,'itm_sesshu_painting',slot_item_jun,100),
			(item_set_slot,'itm_sesshu_painting',slot_item_jul,100),
			(item_set_slot,'itm_sesshu_painting',slot_item_aug,100),
			(item_set_slot,'itm_sesshu_painting',slot_item_sep,100),
			(item_set_slot,'itm_sesshu_painting',slot_item_oct,100),
			(item_set_slot,'itm_sesshu_painting',slot_item_nov,100),
			(item_set_slot,'itm_sesshu_painting',slot_item_dec,100),
			(item_set_slot,'itm_sesshu_painting',slot_item_demand_coefficient,0),

			(item_set_slot,'itm_seto_pottery',slot_item_seaside,0),
			(item_set_slot,'itm_seto_pottery',slot_item_island,0),
			(item_set_slot,'itm_seto_pottery',slot_item_lakeside,0),
			(item_set_slot,'itm_seto_pottery',slot_item_lowland,0),
			(item_set_slot,'itm_seto_pottery',slot_item_highland,0),
			(item_set_slot,'itm_seto_pottery',slot_item_low_valley,0),
			(item_set_slot,'itm_seto_pottery',slot_item_high_valley,0),
			(item_set_slot,'itm_seto_pottery',slot_item_small_village,0),
			(item_set_slot,'itm_seto_pottery',slot_item_village,0),
			(item_set_slot,'itm_seto_pottery',slot_item_large_village,0),
			(item_set_slot,'itm_seto_pottery',slot_item_town,0),
			(item_set_slot,'itm_seto_pottery',slot_item_large_town,0),
			(item_set_slot,'itm_seto_pottery',slot_item_city,100),
			(item_set_slot,'itm_seto_pottery',slot_item_port,0),
			(item_set_slot,'itm_seto_pottery',slot_item_jan,100),
			(item_set_slot,'itm_seto_pottery',slot_item_feb,100),
			(item_set_slot,'itm_seto_pottery',slot_item_mar,100),
			(item_set_slot,'itm_seto_pottery',slot_item_apr,100),
			(item_set_slot,'itm_seto_pottery',slot_item_may,100),
			(item_set_slot,'itm_seto_pottery',slot_item_jun,100),
			(item_set_slot,'itm_seto_pottery',slot_item_jul,100),
			(item_set_slot,'itm_seto_pottery',slot_item_aug,100),
			(item_set_slot,'itm_seto_pottery',slot_item_sep,100),
			(item_set_slot,'itm_seto_pottery',slot_item_oct,100),
			(item_set_slot,'itm_seto_pottery',slot_item_nov,100),
			(item_set_slot,'itm_seto_pottery',slot_item_dec,100),
			(item_set_slot,'itm_seto_pottery',slot_item_demand_coefficient,2),

			(item_set_slot,'itm_sharkskin',slot_item_seaside,25),
			(item_set_slot,'itm_sharkskin',slot_item_island,50),
			(item_set_slot,'itm_sharkskin',slot_item_lakeside,0),
			(item_set_slot,'itm_sharkskin',slot_item_lowland,0),
			(item_set_slot,'itm_sharkskin',slot_item_highland,0),
			(item_set_slot,'itm_sharkskin',slot_item_low_valley,0),
			(item_set_slot,'itm_sharkskin',slot_item_high_valley,0),
			(item_set_slot,'itm_sharkskin',slot_item_small_village,0),
			(item_set_slot,'itm_sharkskin',slot_item_village,0),
			(item_set_slot,'itm_sharkskin',slot_item_large_village,0),
			(item_set_slot,'itm_sharkskin',slot_item_town,0),
			(item_set_slot,'itm_sharkskin',slot_item_large_town,0),
			(item_set_slot,'itm_sharkskin',slot_item_city,0),
			(item_set_slot,'itm_sharkskin',slot_item_port,25),
			(item_set_slot,'itm_sharkskin',slot_item_jan,100),
			(item_set_slot,'itm_sharkskin',slot_item_feb,100),
			(item_set_slot,'itm_sharkskin',slot_item_mar,100),
			(item_set_slot,'itm_sharkskin',slot_item_apr,100),
			(item_set_slot,'itm_sharkskin',slot_item_may,100),
			(item_set_slot,'itm_sharkskin',slot_item_jun,100),
			(item_set_slot,'itm_sharkskin',slot_item_jul,100),
			(item_set_slot,'itm_sharkskin',slot_item_aug,100),
			(item_set_slot,'itm_sharkskin',slot_item_sep,100),
			(item_set_slot,'itm_sharkskin',slot_item_oct,100),
			(item_set_slot,'itm_sharkskin',slot_item_nov,100),
			(item_set_slot,'itm_sharkskin',slot_item_dec,100),
			(item_set_slot,'itm_sharkskin',slot_item_demand_coefficient,0),

			(item_set_slot,'itm_shin_kokinshu',slot_item_seaside,0),
			(item_set_slot,'itm_shin_kokinshu',slot_item_island,0),
			(item_set_slot,'itm_shin_kokinshu',slot_item_lakeside,0),
			(item_set_slot,'itm_shin_kokinshu',slot_item_lowland,0),
			(item_set_slot,'itm_shin_kokinshu',slot_item_highland,0),
			(item_set_slot,'itm_shin_kokinshu',slot_item_low_valley,0),
			(item_set_slot,'itm_shin_kokinshu',slot_item_high_valley,0),
			(item_set_slot,'itm_shin_kokinshu',slot_item_small_village,0),
			(item_set_slot,'itm_shin_kokinshu',slot_item_village,0),
			(item_set_slot,'itm_shin_kokinshu',slot_item_large_village,0),
			(item_set_slot,'itm_shin_kokinshu',slot_item_town,0),
			(item_set_slot,'itm_shin_kokinshu',slot_item_large_town,100),
			(item_set_slot,'itm_shin_kokinshu',slot_item_city,200),
			(item_set_slot,'itm_shin_kokinshu',slot_item_port,0),
			(item_set_slot,'itm_shin_kokinshu',slot_item_jan,100),
			(item_set_slot,'itm_shin_kokinshu',slot_item_feb,100),
			(item_set_slot,'itm_shin_kokinshu',slot_item_mar,100),
			(item_set_slot,'itm_shin_kokinshu',slot_item_apr,100),
			(item_set_slot,'itm_shin_kokinshu',slot_item_may,100),
			(item_set_slot,'itm_shin_kokinshu',slot_item_jun,100),
			(item_set_slot,'itm_shin_kokinshu',slot_item_jul,100),
			(item_set_slot,'itm_shin_kokinshu',slot_item_aug,100),
			(item_set_slot,'itm_shin_kokinshu',slot_item_sep,100),
			(item_set_slot,'itm_shin_kokinshu',slot_item_oct,100),
			(item_set_slot,'itm_shin_kokinshu',slot_item_nov,100),
			(item_set_slot,'itm_shin_kokinshu',slot_item_dec,100),
			(item_set_slot,'itm_shin_kokinshu',slot_item_demand_coefficient,0),

			(item_set_slot,'itm_shingei_painting',slot_item_seaside,0),
			(item_set_slot,'itm_shingei_painting',slot_item_island,0),
			(item_set_slot,'itm_shingei_painting',slot_item_lakeside,0),
			(item_set_slot,'itm_shingei_painting',slot_item_lowland,0),
			(item_set_slot,'itm_shingei_painting',slot_item_highland,0),
			(item_set_slot,'itm_shingei_painting',slot_item_low_valley,0),
			(item_set_slot,'itm_shingei_painting',slot_item_high_valley,0),
			(item_set_slot,'itm_shingei_painting',slot_item_small_village,0),
			(item_set_slot,'itm_shingei_painting',slot_item_village,0),
			(item_set_slot,'itm_shingei_painting',slot_item_large_village,0),
			(item_set_slot,'itm_shingei_painting',slot_item_town,0),
			(item_set_slot,'itm_shingei_painting',slot_item_large_town,100),
			(item_set_slot,'itm_shingei_painting',slot_item_city,200),
			(item_set_slot,'itm_shingei_painting',slot_item_port,0),
			(item_set_slot,'itm_shingei_painting',slot_item_jan,100),
			(item_set_slot,'itm_shingei_painting',slot_item_feb,100),
			(item_set_slot,'itm_shingei_painting',slot_item_mar,100),
			(item_set_slot,'itm_shingei_painting',slot_item_apr,100),
			(item_set_slot,'itm_shingei_painting',slot_item_may,100),
			(item_set_slot,'itm_shingei_painting',slot_item_jun,100),
			(item_set_slot,'itm_shingei_painting',slot_item_jul,100),
			(item_set_slot,'itm_shingei_painting',slot_item_aug,100),
			(item_set_slot,'itm_shingei_painting',slot_item_sep,100),
			(item_set_slot,'itm_shingei_painting',slot_item_oct,100),
			(item_set_slot,'itm_shingei_painting',slot_item_nov,100),
			(item_set_slot,'itm_shingei_painting',slot_item_dec,100),
			(item_set_slot,'itm_shingei_painting',slot_item_demand_coefficient,0),

			(item_set_slot,'itm_shubun_painting',slot_item_seaside,0),
			(item_set_slot,'itm_shubun_painting',slot_item_island,0),
			(item_set_slot,'itm_shubun_painting',slot_item_lakeside,0),
			(item_set_slot,'itm_shubun_painting',slot_item_lowland,0),
			(item_set_slot,'itm_shubun_painting',slot_item_highland,0),
			(item_set_slot,'itm_shubun_painting',slot_item_low_valley,0),
			(item_set_slot,'itm_shubun_painting',slot_item_high_valley,0),
			(item_set_slot,'itm_shubun_painting',slot_item_small_village,0),
			(item_set_slot,'itm_shubun_painting',slot_item_village,0),
			(item_set_slot,'itm_shubun_painting',slot_item_large_village,0),
			(item_set_slot,'itm_shubun_painting',slot_item_town,0),
			(item_set_slot,'itm_shubun_painting',slot_item_large_town,100),
			(item_set_slot,'itm_shubun_painting',slot_item_city,200),
			(item_set_slot,'itm_shubun_painting',slot_item_port,0),
			(item_set_slot,'itm_shubun_painting',slot_item_jan,100),
			(item_set_slot,'itm_shubun_painting',slot_item_feb,100),
			(item_set_slot,'itm_shubun_painting',slot_item_mar,100),
			(item_set_slot,'itm_shubun_painting',slot_item_apr,100),
			(item_set_slot,'itm_shubun_painting',slot_item_may,100),
			(item_set_slot,'itm_shubun_painting',slot_item_jun,100),
			(item_set_slot,'itm_shubun_painting',slot_item_jul,100),
			(item_set_slot,'itm_shubun_painting',slot_item_aug,100),
			(item_set_slot,'itm_shubun_painting',slot_item_sep,100),
			(item_set_slot,'itm_shubun_painting',slot_item_oct,100),
			(item_set_slot,'itm_shubun_painting',slot_item_nov,100),
			(item_set_slot,'itm_shubun_painting',slot_item_dec,100),
			(item_set_slot,'itm_shubun_painting',slot_item_demand_coefficient,0),

			(item_set_slot,'itm_silk',slot_item_seaside,0),
			(item_set_slot,'itm_silk',slot_item_island,0),
			(item_set_slot,'itm_silk',slot_item_lakeside,0),
			(item_set_slot,'itm_silk',slot_item_lowland,0),
			(item_set_slot,'itm_silk',slot_item_highland,0),
			(item_set_slot,'itm_silk',slot_item_low_valley,0),
			(item_set_slot,'itm_silk',slot_item_high_valley,0),
			(item_set_slot,'itm_silk',slot_item_small_village,0),
			(item_set_slot,'itm_silk',slot_item_village,0),
			(item_set_slot,'itm_silk',slot_item_large_village,0),
			(item_set_slot,'itm_silk',slot_item_town,100),
			(item_set_slot,'itm_silk',slot_item_large_town,200),
			(item_set_slot,'itm_silk',slot_item_city,300),
			(item_set_slot,'itm_silk',slot_item_port,0),
			(item_set_slot,'itm_silk',slot_item_jan,100),
			(item_set_slot,'itm_silk',slot_item_feb,100),
			(item_set_slot,'itm_silk',slot_item_mar,100),
			(item_set_slot,'itm_silk',slot_item_apr,100),
			(item_set_slot,'itm_silk',slot_item_may,100),
			(item_set_slot,'itm_silk',slot_item_jun,100),
			(item_set_slot,'itm_silk',slot_item_jul,100),
			(item_set_slot,'itm_silk',slot_item_aug,100),
			(item_set_slot,'itm_silk',slot_item_sep,100),
			(item_set_slot,'itm_silk',slot_item_oct,100),
			(item_set_slot,'itm_silk',slot_item_nov,100),
			(item_set_slot,'itm_silk',slot_item_dec,100),
			(item_set_slot,'itm_silk',slot_item_demand_coefficient,100),

			(item_set_slot,'itm_silver_bars',slot_item_seaside,0),
			(item_set_slot,'itm_silver_bars',slot_item_island,0),
			(item_set_slot,'itm_silver_bars',slot_item_lakeside,0),
			(item_set_slot,'itm_silver_bars',slot_item_lowland,0),
			(item_set_slot,'itm_silver_bars',slot_item_highland,0),
			(item_set_slot,'itm_silver_bars',slot_item_low_valley,0),
			(item_set_slot,'itm_silver_bars',slot_item_high_valley,0),
			(item_set_slot,'itm_silver_bars',slot_item_small_village,0),
			(item_set_slot,'itm_silver_bars',slot_item_village,0),
			(item_set_slot,'itm_silver_bars',slot_item_large_village,0),
			(item_set_slot,'itm_silver_bars',slot_item_town,0),
			(item_set_slot,'itm_silver_bars',slot_item_large_town,0),
			(item_set_slot,'itm_silver_bars',slot_item_city,0),
			(item_set_slot,'itm_silver_bars',slot_item_port,0),
			(item_set_slot,'itm_silver_bars',slot_item_jan,100),
			(item_set_slot,'itm_silver_bars',slot_item_feb,100),
			(item_set_slot,'itm_silver_bars',slot_item_mar,100),
			(item_set_slot,'itm_silver_bars',slot_item_apr,100),
			(item_set_slot,'itm_silver_bars',slot_item_may,100),
			(item_set_slot,'itm_silver_bars',slot_item_jun,100),
			(item_set_slot,'itm_silver_bars',slot_item_jul,100),
			(item_set_slot,'itm_silver_bars',slot_item_aug,100),
			(item_set_slot,'itm_silver_bars',slot_item_sep,100),
			(item_set_slot,'itm_silver_bars',slot_item_oct,100),
			(item_set_slot,'itm_silver_bars',slot_item_nov,100),
			(item_set_slot,'itm_silver_bars',slot_item_dec,100),
			(item_set_slot,'itm_silver_bars',slot_item_demand_coefficient,0),

			(item_set_slot,'itm_silver_ore',slot_item_seaside,0),
			(item_set_slot,'itm_silver_ore',slot_item_island,0),
			(item_set_slot,'itm_silver_ore',slot_item_lakeside,0),
			(item_set_slot,'itm_silver_ore',slot_item_lowland,0),
			(item_set_slot,'itm_silver_ore',slot_item_highland,0),
			(item_set_slot,'itm_silver_ore',slot_item_low_valley,0),
			(item_set_slot,'itm_silver_ore',slot_item_high_valley,0),
			(item_set_slot,'itm_silver_ore',slot_item_small_village,0),
			(item_set_slot,'itm_silver_ore',slot_item_village,0),
			(item_set_slot,'itm_silver_ore',slot_item_large_village,0),
			(item_set_slot,'itm_silver_ore',slot_item_town,0),
			(item_set_slot,'itm_silver_ore',slot_item_large_town,0),
			(item_set_slot,'itm_silver_ore',slot_item_city,0),
			(item_set_slot,'itm_silver_ore',slot_item_port,0),
			(item_set_slot,'itm_silver_ore',slot_item_jan,0),
			(item_set_slot,'itm_silver_ore',slot_item_feb,0),
			(item_set_slot,'itm_silver_ore',slot_item_mar,0),
			(item_set_slot,'itm_silver_ore',slot_item_apr,0),
			(item_set_slot,'itm_silver_ore',slot_item_may,0),
			(item_set_slot,'itm_silver_ore',slot_item_jun,0),
			(item_set_slot,'itm_silver_ore',slot_item_jul,0),
			(item_set_slot,'itm_silver_ore',slot_item_aug,0),
			(item_set_slot,'itm_silver_ore',slot_item_sep,0),
			(item_set_slot,'itm_silver_ore',slot_item_oct,0),
			(item_set_slot,'itm_silver_ore',slot_item_nov,0),
			(item_set_slot,'itm_silver_ore',slot_item_dec,0),
			(item_set_slot,'itm_silver_ore',slot_item_demand_coefficient,0),

			(item_set_slot,'itm_smoked_fish',slot_item_seaside,700),
			(item_set_slot,'itm_smoked_fish',slot_item_island,700),
			(item_set_slot,'itm_smoked_fish',slot_item_lakeside,600),
			(item_set_slot,'itm_smoked_fish',slot_item_lowland,200),
			(item_set_slot,'itm_smoked_fish',slot_item_highland,0),
			(item_set_slot,'itm_smoked_fish',slot_item_low_valley,0),
			(item_set_slot,'itm_smoked_fish',slot_item_high_valley,0),
			(item_set_slot,'itm_smoked_fish',slot_item_small_village,0),
			(item_set_slot,'itm_smoked_fish',slot_item_village,0),
			(item_set_slot,'itm_smoked_fish',slot_item_large_village,0),
			(item_set_slot,'itm_smoked_fish',slot_item_town,0),
			(item_set_slot,'itm_smoked_fish',slot_item_large_town,100),
			(item_set_slot,'itm_smoked_fish',slot_item_city,200),
			(item_set_slot,'itm_smoked_fish',slot_item_port,0),
			(item_set_slot,'itm_smoked_fish',slot_item_jan,100),
			(item_set_slot,'itm_smoked_fish',slot_item_feb,100),
			(item_set_slot,'itm_smoked_fish',slot_item_mar,100),
			(item_set_slot,'itm_smoked_fish',slot_item_apr,100),
			(item_set_slot,'itm_smoked_fish',slot_item_may,100),
			(item_set_slot,'itm_smoked_fish',slot_item_jun,100),
			(item_set_slot,'itm_smoked_fish',slot_item_jul,100),
			(item_set_slot,'itm_smoked_fish',slot_item_aug,100),
			(item_set_slot,'itm_smoked_fish',slot_item_sep,100),
			(item_set_slot,'itm_smoked_fish',slot_item_oct,100),
			(item_set_slot,'itm_smoked_fish',slot_item_nov,100),
			(item_set_slot,'itm_smoked_fish',slot_item_dec,100),
			(item_set_slot,'itm_smoked_fish',slot_item_demand_coefficient,0),

			(item_set_slot,'itm_soya',slot_item_seaside,0),
			(item_set_slot,'itm_soya',slot_item_island,0),
			(item_set_slot,'itm_soya',slot_item_lakeside,0),
			(item_set_slot,'itm_soya',slot_item_lowland,0),
			(item_set_slot,'itm_soya',slot_item_highland,0),
			(item_set_slot,'itm_soya',slot_item_low_valley,0),
			(item_set_slot,'itm_soya',slot_item_high_valley,0),
			(item_set_slot,'itm_soya',slot_item_small_village,0),
			(item_set_slot,'itm_soya',slot_item_village,0),
			(item_set_slot,'itm_soya',slot_item_large_village,0),
			(item_set_slot,'itm_soya',slot_item_town,100),
			(item_set_slot,'itm_soya',slot_item_large_town,200),
			(item_set_slot,'itm_soya',slot_item_city,300),
			(item_set_slot,'itm_soya',slot_item_port,0),
			(item_set_slot,'itm_soya',slot_item_jan,100),
			(item_set_slot,'itm_soya',slot_item_feb,100),
			(item_set_slot,'itm_soya',slot_item_mar,100),
			(item_set_slot,'itm_soya',slot_item_apr,100),
			(item_set_slot,'itm_soya',slot_item_may,100),
			(item_set_slot,'itm_soya',slot_item_jun,100),
			(item_set_slot,'itm_soya',slot_item_jul,100),
			(item_set_slot,'itm_soya',slot_item_aug,100),
			(item_set_slot,'itm_soya',slot_item_sep,100),
			(item_set_slot,'itm_soya',slot_item_oct,100),
			(item_set_slot,'itm_soya',slot_item_nov,100),
			(item_set_slot,'itm_soya',slot_item_dec,100),
			(item_set_slot,'itm_soya',slot_item_demand_coefficient,0),

			(item_set_slot,'itm_soybeans',slot_item_seaside,100),
			(item_set_slot,'itm_soybeans',slot_item_island,0),
			(item_set_slot,'itm_soybeans',slot_item_lakeside,100),
			(item_set_slot,'itm_soybeans',slot_item_lowland,400),
			(item_set_slot,'itm_soybeans',slot_item_highland,0),
			(item_set_slot,'itm_soybeans',slot_item_low_valley,0),
			(item_set_slot,'itm_soybeans',slot_item_high_valley,0),
			(item_set_slot,'itm_soybeans',slot_item_small_village,0),
			(item_set_slot,'itm_soybeans',slot_item_village,0),
			(item_set_slot,'itm_soybeans',slot_item_large_village,100),
			(item_set_slot,'itm_soybeans',slot_item_town,0),
			(item_set_slot,'itm_soybeans',slot_item_large_town,0),
			(item_set_slot,'itm_soybeans',slot_item_city,0),
			(item_set_slot,'itm_soybeans',slot_item_port,0),
			(item_set_slot,'itm_soybeans',slot_item_jan,0),
			(item_set_slot,'itm_soybeans',slot_item_feb,0),
			(item_set_slot,'itm_soybeans',slot_item_mar,0),
			(item_set_slot,'itm_soybeans',slot_item_apr,0),
			(item_set_slot,'itm_soybeans',slot_item_may,0),
			(item_set_slot,'itm_soybeans',slot_item_jun,30),
			(item_set_slot,'itm_soybeans',slot_item_jul,100),
			(item_set_slot,'itm_soybeans',slot_item_aug,80),
			(item_set_slot,'itm_soybeans',slot_item_sep,50),
			(item_set_slot,'itm_soybeans',slot_item_oct,20),
			(item_set_slot,'itm_soybeans',slot_item_nov,0),
			(item_set_slot,'itm_soybeans',slot_item_dec,0),
			(item_set_slot,'itm_soybeans',slot_item_demand_coefficient,0),

			(item_set_slot,'itm_sushi_fish',slot_item_seaside,600),
			(item_set_slot,'itm_sushi_fish',slot_item_island,600),
			(item_set_slot,'itm_sushi_fish',slot_item_lakeside,500),
			(item_set_slot,'itm_sushi_fish',slot_item_lowland,100),
			(item_set_slot,'itm_sushi_fish',slot_item_highland,0),
			(item_set_slot,'itm_sushi_fish',slot_item_low_valley,0),
			(item_set_slot,'itm_sushi_fish',slot_item_high_valley,0),
			(item_set_slot,'itm_sushi_fish',slot_item_small_village,0),
			(item_set_slot,'itm_sushi_fish',slot_item_village,0),
			(item_set_slot,'itm_sushi_fish',slot_item_large_village,0),
			(item_set_slot,'itm_sushi_fish',slot_item_town,100),
			(item_set_slot,'itm_sushi_fish',slot_item_large_town,200),
			(item_set_slot,'itm_sushi_fish',slot_item_city,300),
			(item_set_slot,'itm_sushi_fish',slot_item_port,0),
			(item_set_slot,'itm_sushi_fish',slot_item_jan,100),
			(item_set_slot,'itm_sushi_fish',slot_item_feb,100),
			(item_set_slot,'itm_sushi_fish',slot_item_mar,100),
			(item_set_slot,'itm_sushi_fish',slot_item_apr,100),
			(item_set_slot,'itm_sushi_fish',slot_item_may,100),
			(item_set_slot,'itm_sushi_fish',slot_item_jun,100),
			(item_set_slot,'itm_sushi_fish',slot_item_jul,100),
			(item_set_slot,'itm_sushi_fish',slot_item_aug,100),
			(item_set_slot,'itm_sushi_fish',slot_item_sep,100),
			(item_set_slot,'itm_sushi_fish',slot_item_oct,100),
			(item_set_slot,'itm_sushi_fish',slot_item_nov,100),
			(item_set_slot,'itm_sushi_fish',slot_item_dec,100),
			(item_set_slot,'itm_sushi_fish',slot_item_demand_coefficient,0),

			(item_set_slot,'itm_taiko_drum',slot_item_seaside,0),
			(item_set_slot,'itm_taiko_drum',slot_item_island,0),
			(item_set_slot,'itm_taiko_drum',slot_item_lakeside,0),
			(item_set_slot,'itm_taiko_drum',slot_item_lowland,0),
			(item_set_slot,'itm_taiko_drum',slot_item_highland,0),
			(item_set_slot,'itm_taiko_drum',slot_item_low_valley,0),
			(item_set_slot,'itm_taiko_drum',slot_item_high_valley,100),
			(item_set_slot,'itm_taiko_drum',slot_item_small_village,0),
			(item_set_slot,'itm_taiko_drum',slot_item_village,0),
			(item_set_slot,'itm_taiko_drum',slot_item_large_village,0),
			(item_set_slot,'itm_taiko_drum',slot_item_town,0),
			(item_set_slot,'itm_taiko_drum',slot_item_large_town,0),
			(item_set_slot,'itm_taiko_drum',slot_item_city,100),
			(item_set_slot,'itm_taiko_drum',slot_item_port,0),
			(item_set_slot,'itm_taiko_drum',slot_item_jan,100),
			(item_set_slot,'itm_taiko_drum',slot_item_feb,100),
			(item_set_slot,'itm_taiko_drum',slot_item_mar,100),
			(item_set_slot,'itm_taiko_drum',slot_item_apr,100),
			(item_set_slot,'itm_taiko_drum',slot_item_may,100),
			(item_set_slot,'itm_taiko_drum',slot_item_jun,100),
			(item_set_slot,'itm_taiko_drum',slot_item_jul,100),
			(item_set_slot,'itm_taiko_drum',slot_item_aug,100),
			(item_set_slot,'itm_taiko_drum',slot_item_sep,100),
			(item_set_slot,'itm_taiko_drum',slot_item_oct,100),
			(item_set_slot,'itm_taiko_drum',slot_item_nov,100),
			(item_set_slot,'itm_taiko_drum',slot_item_dec,100),
			(item_set_slot,'itm_taiko_drum',slot_item_demand_coefficient,0),

			(item_set_slot,'itm_tamahagane_nugget',slot_item_seaside,0),
			(item_set_slot,'itm_tamahagane_nugget',slot_item_island,0),
			(item_set_slot,'itm_tamahagane_nugget',slot_item_lakeside,0),
			(item_set_slot,'itm_tamahagane_nugget',slot_item_lowland,0),
			(item_set_slot,'itm_tamahagane_nugget',slot_item_highland,100),
			(item_set_slot,'itm_tamahagane_nugget',slot_item_low_valley,0),
			(item_set_slot,'itm_tamahagane_nugget',slot_item_high_valley,100),
			(item_set_slot,'itm_tamahagane_nugget',slot_item_small_village,0),
			(item_set_slot,'itm_tamahagane_nugget',slot_item_village,0),
			(item_set_slot,'itm_tamahagane_nugget',slot_item_large_village,0),
			(item_set_slot,'itm_tamahagane_nugget',slot_item_town,0),
			(item_set_slot,'itm_tamahagane_nugget',slot_item_large_town,100),
			(item_set_slot,'itm_tamahagane_nugget',slot_item_city,200),
			(item_set_slot,'itm_tamahagane_nugget',slot_item_port,0),
			(item_set_slot,'itm_tamahagane_nugget',slot_item_jan,100),
			(item_set_slot,'itm_tamahagane_nugget',slot_item_feb,100),
			(item_set_slot,'itm_tamahagane_nugget',slot_item_mar,100),
			(item_set_slot,'itm_tamahagane_nugget',slot_item_apr,100),
			(item_set_slot,'itm_tamahagane_nugget',slot_item_may,100),
			(item_set_slot,'itm_tamahagane_nugget',slot_item_jun,100),
			(item_set_slot,'itm_tamahagane_nugget',slot_item_jul,100),
			(item_set_slot,'itm_tamahagane_nugget',slot_item_aug,100),
			(item_set_slot,'itm_tamahagane_nugget',slot_item_sep,100),
			(item_set_slot,'itm_tamahagane_nugget',slot_item_oct,100),
			(item_set_slot,'itm_tamahagane_nugget',slot_item_nov,100),
			(item_set_slot,'itm_tamahagane_nugget',slot_item_dec,100),
			(item_set_slot,'itm_tamahagane_nugget',slot_item_demand_coefficient,0),

			(item_set_slot,'itm_tatami',slot_item_seaside,0),
			(item_set_slot,'itm_tatami',slot_item_island,0),
			(item_set_slot,'itm_tatami',slot_item_lakeside,100),
			(item_set_slot,'itm_tatami',slot_item_lowland,200),
			(item_set_slot,'itm_tatami',slot_item_highland,100),
			(item_set_slot,'itm_tatami',slot_item_low_valley,100),
			(item_set_slot,'itm_tatami',slot_item_high_valley,0),
			(item_set_slot,'itm_tatami',slot_item_small_village,0),
			(item_set_slot,'itm_tatami',slot_item_village,0),
			(item_set_slot,'itm_tatami',slot_item_large_village,100),
			(item_set_slot,'itm_tatami',slot_item_town,0),
			(item_set_slot,'itm_tatami',slot_item_large_town,0),
			(item_set_slot,'itm_tatami',slot_item_city,0),
			(item_set_slot,'itm_tatami',slot_item_port,0),
			(item_set_slot,'itm_tatami',slot_item_jan,80),
			(item_set_slot,'itm_tatami',slot_item_feb,60),
			(item_set_slot,'itm_tatami',slot_item_mar,30),
			(item_set_slot,'itm_tatami',slot_item_apr,20),
			(item_set_slot,'itm_tatami',slot_item_may,20),
			(item_set_slot,'itm_tatami',slot_item_jun,20),
			(item_set_slot,'itm_tatami',slot_item_jul,20),
			(item_set_slot,'itm_tatami',slot_item_aug,20),
			(item_set_slot,'itm_tatami',slot_item_sep,20),
			(item_set_slot,'itm_tatami',slot_item_oct,100),
			(item_set_slot,'itm_tatami',slot_item_nov,100),
			(item_set_slot,'itm_tatami',slot_item_dec,100),
			(item_set_slot,'itm_tatami',slot_item_demand_coefficient,0),

			(item_set_slot,'itm_tea_leaves',slot_item_seaside,0),
			(item_set_slot,'itm_tea_leaves',slot_item_island,0),
			(item_set_slot,'itm_tea_leaves',slot_item_lakeside,0),
			(item_set_slot,'itm_tea_leaves',slot_item_lowland,100),
			(item_set_slot,'itm_tea_leaves',slot_item_highland,100),
			(item_set_slot,'itm_tea_leaves',slot_item_low_valley,0),
			(item_set_slot,'itm_tea_leaves',slot_item_high_valley,0),
			(item_set_slot,'itm_tea_leaves',slot_item_small_village,0),
			(item_set_slot,'itm_tea_leaves',slot_item_village,0),
			(item_set_slot,'itm_tea_leaves',slot_item_large_village,0),
			(item_set_slot,'itm_tea_leaves',slot_item_town,100),
			(item_set_slot,'itm_tea_leaves',slot_item_large_town,200),
			(item_set_slot,'itm_tea_leaves',slot_item_city,300),
			(item_set_slot,'itm_tea_leaves',slot_item_port,0),
			(item_set_slot,'itm_tea_leaves',slot_item_jan,0),
			(item_set_slot,'itm_tea_leaves',slot_item_feb,0),
			(item_set_slot,'itm_tea_leaves',slot_item_mar,0),
			(item_set_slot,'itm_tea_leaves',slot_item_apr,0),
			(item_set_slot,'itm_tea_leaves',slot_item_may,0),
			(item_set_slot,'itm_tea_leaves',slot_item_jun,0),
			(item_set_slot,'itm_tea_leaves',slot_item_jul,100),
			(item_set_slot,'itm_tea_leaves',slot_item_aug,80),
			(item_set_slot,'itm_tea_leaves',slot_item_sep,50),
			(item_set_slot,'itm_tea_leaves',slot_item_oct,20),
			(item_set_slot,'itm_tea_leaves',slot_item_nov,0),
			(item_set_slot,'itm_tea_leaves',slot_item_dec,0),
			(item_set_slot,'itm_tea_leaves',slot_item_demand_coefficient,0),

			(item_set_slot,'itm_tendai_charm',slot_item_seaside,0),
			(item_set_slot,'itm_tendai_charm',slot_item_island,0),
			(item_set_slot,'itm_tendai_charm',slot_item_lakeside,0),
			(item_set_slot,'itm_tendai_charm',slot_item_lowland,0),
			(item_set_slot,'itm_tendai_charm',slot_item_highland,0),
			(item_set_slot,'itm_tendai_charm',slot_item_low_valley,0),
			(item_set_slot,'itm_tendai_charm',slot_item_high_valley,0),
			(item_set_slot,'itm_tendai_charm',slot_item_small_village,0),
			(item_set_slot,'itm_tendai_charm',slot_item_village,0),
			(item_set_slot,'itm_tendai_charm',slot_item_large_village,0),
			(item_set_slot,'itm_tendai_charm',slot_item_town,0),
			(item_set_slot,'itm_tendai_charm',slot_item_large_town,100),
			(item_set_slot,'itm_tendai_charm',slot_item_city,200),
			(item_set_slot,'itm_tendai_charm',slot_item_port,0),
			(item_set_slot,'itm_tendai_charm',slot_item_jan,100),
			(item_set_slot,'itm_tendai_charm',slot_item_feb,100),
			(item_set_slot,'itm_tendai_charm',slot_item_mar,100),
			(item_set_slot,'itm_tendai_charm',slot_item_apr,100),
			(item_set_slot,'itm_tendai_charm',slot_item_may,100),
			(item_set_slot,'itm_tendai_charm',slot_item_jun,100),
			(item_set_slot,'itm_tendai_charm',slot_item_jul,100),
			(item_set_slot,'itm_tendai_charm',slot_item_aug,100),
			(item_set_slot,'itm_tendai_charm',slot_item_sep,100),
			(item_set_slot,'itm_tendai_charm',slot_item_oct,100),
			(item_set_slot,'itm_tendai_charm',slot_item_nov,100),
			(item_set_slot,'itm_tendai_charm',slot_item_dec,100),
			(item_set_slot,'itm_tendai_charm',slot_item_demand_coefficient,0),

			(item_set_slot,'itm_tsurezuregusa',slot_item_seaside,0),
			(item_set_slot,'itm_tsurezuregusa',slot_item_island,0),
			(item_set_slot,'itm_tsurezuregusa',slot_item_lakeside,0),
			(item_set_slot,'itm_tsurezuregusa',slot_item_lowland,0),
			(item_set_slot,'itm_tsurezuregusa',slot_item_highland,0),
			(item_set_slot,'itm_tsurezuregusa',slot_item_low_valley,0),
			(item_set_slot,'itm_tsurezuregusa',slot_item_high_valley,0),
			(item_set_slot,'itm_tsurezuregusa',slot_item_small_village,0),
			(item_set_slot,'itm_tsurezuregusa',slot_item_village,0),
			(item_set_slot,'itm_tsurezuregusa',slot_item_large_village,0),
			(item_set_slot,'itm_tsurezuregusa',slot_item_town,0),
			(item_set_slot,'itm_tsurezuregusa',slot_item_large_town,0),
			(item_set_slot,'itm_tsurezuregusa',slot_item_city,100),
			(item_set_slot,'itm_tsurezuregusa',slot_item_port,0),
			(item_set_slot,'itm_tsurezuregusa',slot_item_jan,100),
			(item_set_slot,'itm_tsurezuregusa',slot_item_feb,100),
			(item_set_slot,'itm_tsurezuregusa',slot_item_mar,100),
			(item_set_slot,'itm_tsurezuregusa',slot_item_apr,100),
			(item_set_slot,'itm_tsurezuregusa',slot_item_may,100),
			(item_set_slot,'itm_tsurezuregusa',slot_item_jun,100),
			(item_set_slot,'itm_tsurezuregusa',slot_item_jul,100),
			(item_set_slot,'itm_tsurezuregusa',slot_item_aug,100),
			(item_set_slot,'itm_tsurezuregusa',slot_item_sep,100),
			(item_set_slot,'itm_tsurezuregusa',slot_item_oct,100),
			(item_set_slot,'itm_tsurezuregusa',slot_item_nov,100),
			(item_set_slot,'itm_tsurezuregusa',slot_item_dec,100),
			(item_set_slot,'itm_tsurezuregusa',slot_item_demand_coefficient,0),

			(item_set_slot,'itm_wheat',slot_item_seaside,500),
			(item_set_slot,'itm_wheat',slot_item_island,400),
			(item_set_slot,'itm_wheat',slot_item_lakeside,500),
			(item_set_slot,'itm_wheat',slot_item_lowland,600),
			(item_set_slot,'itm_wheat',slot_item_highland,400),
			(item_set_slot,'itm_wheat',slot_item_low_valley,300),
			(item_set_slot,'itm_wheat',slot_item_high_valley,200),
			(item_set_slot,'itm_wheat',slot_item_small_village,0),
			(item_set_slot,'itm_wheat',slot_item_village,0),
			(item_set_slot,'itm_wheat',slot_item_large_village,100),
			(item_set_slot,'itm_wheat',slot_item_town,100),
			(item_set_slot,'itm_wheat',slot_item_large_town,0),
			(item_set_slot,'itm_wheat',slot_item_city,0),
			(item_set_slot,'itm_wheat',slot_item_port,0),
			(item_set_slot,'itm_wheat',slot_item_jan,15),
			(item_set_slot,'itm_wheat',slot_item_feb,10),
			(item_set_slot,'itm_wheat',slot_item_mar,5),
			(item_set_slot,'itm_wheat',slot_item_apr,0),
			(item_set_slot,'itm_wheat',slot_item_may,0),
			(item_set_slot,'itm_wheat',slot_item_jun,100),
			(item_set_slot,'itm_wheat',slot_item_jul,90),
			(item_set_slot,'itm_wheat',slot_item_aug,75),
			(item_set_slot,'itm_wheat',slot_item_sep,50),
			(item_set_slot,'itm_wheat',slot_item_oct,35),
			(item_set_slot,'itm_wheat',slot_item_nov,25),
			(item_set_slot,'itm_wheat',slot_item_dec,20),
			(item_set_slot,'itm_wheat',slot_item_demand_coefficient,0),

			(item_set_slot,'itm_wooden_tools',slot_item_seaside,100),
			(item_set_slot,'itm_wooden_tools',slot_item_island,0),
			(item_set_slot,'itm_wooden_tools',slot_item_lakeside,100),
			(item_set_slot,'itm_wooden_tools',slot_item_lowland,100),
			(item_set_slot,'itm_wooden_tools',slot_item_highland,200),
			(item_set_slot,'itm_wooden_tools',slot_item_low_valley,100),
			(item_set_slot,'itm_wooden_tools',slot_item_high_valley,100),
			(item_set_slot,'itm_wooden_tools',slot_item_small_village,0),
			(item_set_slot,'itm_wooden_tools',slot_item_village,100),
			(item_set_slot,'itm_wooden_tools',slot_item_large_village,200),
			(item_set_slot,'itm_wooden_tools',slot_item_town,0),
			(item_set_slot,'itm_wooden_tools',slot_item_large_town,0),
			(item_set_slot,'itm_wooden_tools',slot_item_city,0),
			(item_set_slot,'itm_wooden_tools',slot_item_port,0),
			(item_set_slot,'itm_wooden_tools',slot_item_jan,100),
			(item_set_slot,'itm_wooden_tools',slot_item_feb,100),
			(item_set_slot,'itm_wooden_tools',slot_item_mar,100),
			(item_set_slot,'itm_wooden_tools',slot_item_apr,100),
			(item_set_slot,'itm_wooden_tools',slot_item_may,100),
			(item_set_slot,'itm_wooden_tools',slot_item_jun,100),
			(item_set_slot,'itm_wooden_tools',slot_item_jul,100),
			(item_set_slot,'itm_wooden_tools',slot_item_aug,100),
			(item_set_slot,'itm_wooden_tools',slot_item_sep,100),
			(item_set_slot,'itm_wooden_tools',slot_item_oct,100),
			(item_set_slot,'itm_wooden_tools',slot_item_nov,100),
			(item_set_slot,'itm_wooden_tools',slot_item_dec,100),
			(item_set_slot,'itm_wooden_tools',slot_item_demand_coefficient,0),

			(item_set_slot,'itm_wool',slot_item_seaside,0),
			(item_set_slot,'itm_wool',slot_item_island,0),
			(item_set_slot,'itm_wool',slot_item_lakeside,0),
			(item_set_slot,'itm_wool',slot_item_lowland,0),
			(item_set_slot,'itm_wool',slot_item_highland,0),
			(item_set_slot,'itm_wool',slot_item_low_valley,0),
			(item_set_slot,'itm_wool',slot_item_high_valley,0),
			(item_set_slot,'itm_wool',slot_item_small_village,0),
			(item_set_slot,'itm_wool',slot_item_village,0),
			(item_set_slot,'itm_wool',slot_item_large_village,0),
			(item_set_slot,'itm_wool',slot_item_town,0),
			(item_set_slot,'itm_wool',slot_item_large_town,0),
			(item_set_slot,'itm_wool',slot_item_city,0),
			(item_set_slot,'itm_wool',slot_item_port,0),
			(item_set_slot,'itm_wool',slot_item_jan,0),
			(item_set_slot,'itm_wool',slot_item_feb,0),
			(item_set_slot,'itm_wool',slot_item_mar,0),
			(item_set_slot,'itm_wool',slot_item_apr,0),
			(item_set_slot,'itm_wool',slot_item_may,0),
			(item_set_slot,'itm_wool',slot_item_jun,0),
			(item_set_slot,'itm_wool',slot_item_jul,0),
			(item_set_slot,'itm_wool',slot_item_aug,0),
			(item_set_slot,'itm_wool',slot_item_sep,0),
			(item_set_slot,'itm_wool',slot_item_oct,0),
			(item_set_slot,'itm_wool',slot_item_nov,0),
			(item_set_slot,'itm_wool',slot_item_dec,0),
			(item_set_slot,'itm_wool',slot_item_demand_coefficient,0),

			(item_set_slot,'itm_yams',slot_item_seaside,0),
			(item_set_slot,'itm_yams',slot_item_island,0),
			(item_set_slot,'itm_yams',slot_item_lakeside,0),
			(item_set_slot,'itm_yams',slot_item_lowland,200),
			(item_set_slot,'itm_yams',slot_item_highland,0),
			(item_set_slot,'itm_yams',slot_item_low_valley,0),
			(item_set_slot,'itm_yams',slot_item_high_valley,0),
			(item_set_slot,'itm_yams',slot_item_small_village,0),
			(item_set_slot,'itm_yams',slot_item_village,0),
			(item_set_slot,'itm_yams',slot_item_large_village,100),
			(item_set_slot,'itm_yams',slot_item_town,100),
			(item_set_slot,'itm_yams',slot_item_large_town,0),
			(item_set_slot,'itm_yams',slot_item_city,0),
			(item_set_slot,'itm_yams',slot_item_port,0),
			(item_set_slot,'itm_yams',slot_item_jan,0),
			(item_set_slot,'itm_yams',slot_item_feb,0),
			(item_set_slot,'itm_yams',slot_item_mar,0),
			(item_set_slot,'itm_yams',slot_item_apr,100),
			(item_set_slot,'itm_yams',slot_item_may,100),
			(item_set_slot,'itm_yams',slot_item_jun,80),
			(item_set_slot,'itm_yams',slot_item_jul,60),
			(item_set_slot,'itm_yams',slot_item_aug,30),
			(item_set_slot,'itm_yams',slot_item_sep,0),
			(item_set_slot,'itm_yams',slot_item_oct,0),
			(item_set_slot,'itm_yams',slot_item_nov,0),
			(item_set_slot,'itm_yams',slot_item_dec,0),
			(item_set_slot,'itm_yams',slot_item_demand_coefficient,0),

# Initialize cities
			(party_set_slot,'p_city_1',slot_town_center,0),
			(party_set_slot,'p_city_1',slot_town_castle,0),
			(party_set_slot,'p_city_1',slot_town_inn,0),
			(party_set_slot,'p_city_1',slot_town_store,0),
			(party_set_slot,'p_city_1',slot_town_smithy,0),
			(party_set_slot,'p_city_1',slot_town_capital,south_kyoto),
			(party_set_slot,'p_city_1',slot_town_dojo,'scn_south_kyoto_dojo'),
			(party_set_slot,'p_city_1',slot_town_sensei,'trp_mitsumaru'),
			(party_set_slot,'p_city_1',slot_town_kokujin,'trp_city_1_kokujin'),
			(party_set_slot,'p_city_1',slot_town_shugo,-1),
			(party_set_slot,'p_city_1',slot_town_innkeeper,'trp_city_1_innkeeper'),
			(party_set_slot,'p_city_1',slot_town_weaponsmith,'trp_city_1_weaponsmith'),
			(party_set_slot,'p_city_1',slot_town_armorer,'trp_city_1_armorer'),
			(party_set_slot,'p_city_1',slot_town_merchant,'trp_city_1_merchant'),
			(party_set_slot,'p_city_1',slot_town_broker,'trp_broker_15'),
			(party_set_slot,'p_city_1',slot_town_moneychanger,'trp_moneychanger_1'),
			(party_set_slot,'p_city_1',slot_town_fishmonger,'trp_city_1_fishmonger'),
			(party_set_slot,'p_city_1',slot_town_horse_trader,null),
			(party_set_slot,'p_city_1',slot_town_export_good,itm_kyoto_sake),
			(party_set_slot,'p_city_1',slot_town_export_rate,100),
			(party_set_slot,'p_city_1',slot_town_import_good,itm_salt),
			(party_set_slot,'p_city_1',slot_town_import_rate,100),
			(party_set_slot,'p_city_1',slot_town_terrain,ter_highland),
			(party_set_slot,'p_city_1',slot_town_size,ct_city),
			(party_set_slot,'p_city_1',slot_town_mercs,'p_city_1_mercs'),
			(party_set_slot,'p_city_1',slot_town_trade_hub,1),
			(party_set_slot,'p_city_1',slot_town_trade_dest,-1),
			(party_set_slot,'p_city_1',slot_town_trade_month,-1),
			(party_set_slot,'p_city_1',slot_town_att_to_player,att_cautious),
			(party_set_slot,'p_city_1',slot_town_player_relation,0),
			(party_set_slot,'p_city_1',slot_town_import_demand,3),
			(party_set_slot,'p_city_1',slot_town_export_demand,3),
			(party_set_slot,'p_city_1',slot_town_demand,0),
			(call_script,'script_town_init_trade_dest','p_city_1',null,null,null,null,null,null),
			(party_set_slot,'p_city_1',slot_town_treasury,36000),
			(party_set_slot,'p_city_1',slot_town_garrison_source,'p_city_garrison_source'),
			(party_set_slot,'p_city_1',slot_town_siege_active,0),
			(party_set_slot,'p_city_1',slot_town_under_siege,false),
			(party_set_slot,'p_city_1',slot_town_is_besieged_by,null),
			(party_set_slot,'p_city_1',slot_town_initial_faction,0),
			(party_set_slot,'p_city_1',slot_town_scene_flags,0),
			(party_set_slot,'p_city_1',slot_town_reserve_patrol,-1),
			(party_set_slot,'p_city_1',slot_town_spawn_points,10000),
			(party_set_slot,'p_city_1',slot_party_type,spt_city),
			(party_set_slot,'p_city_1',slot_party_food,100000),
			(party_set_slot,'p_city_1',slot_party_icon,'icon_town'),
			(party_set_slot,'p_city_1',slot_party_icon_state,tis_normal),
			(party_set_slot,'p_city_1',slot_party_ai_state,null),
			(party_set_slot,'p_city_1',slot_party_ai_object,null),
			(party_set_slot,'p_city_1',slot_town_accumulated_rents,0),
			(party_set_slot,'p_city_1',slot_town_accumulated_tariffs,0),
			(party_set_slot,'p_city_1',slot_town_current_improvement,null),
			(party_set_slot,'p_city_1',slot_town_improvement_end_hour,null),
			(party_set_slot,'p_city_1',slot_town_housing_level,1),
			(party_set_slot,'p_city_1',slot_town_irrigation_level,1),
			(party_set_slot,'p_city_1',slot_town_mill_level,1),
			(party_set_slot,'p_city_1',slot_town_raided_by,null),
			(party_set_slot,'p_city_1',slot_town_state,sts_normal),
			(party_set_slot,'p_city_1',slot_town_raid_progress,null),
			(party_set_slot,'p_city_1',slot_town_recover_progress,null),
			(party_set_slot,'p_city_1',slot_town_production_bonus,1),
			(party_set_slot,'p_city_1',slot_town_siege_days,0),
			(party_set_slot,'p_city_1',slot_town_reserve_patrol,null),
			(party_set_slot,'p_city_1',slot_town_trade_good_productions_begin,null),
			(party_set_slot,'p_city_1',slot_town_trade_good_temp_productions_begin,null),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_city_1',slot_town_trade_good_price_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_city_1',slot_town_trade_good_abundance_array,'$return'),
			(party_set_slot,'p_city_1',slot_town_tax_rate,100),
			(party_set_slot,'p_city_1',slot_town_shoen,null),
			(party_set_slot,'p_city_1',slot_town_prefecture_array,null),
			(party_set_slot,'p_city_1',slot_town_reinforcements_a,'pt_city_reinforcements_a'),
			(party_set_slot,'p_city_1',slot_town_reinforcements_b,'pt_city_reinforcements_b'),
			(party_set_slot,'p_city_1',slot_town_reinforcements_c,'pt_city_reinforcements_c'),
			(party_set_slot,'p_city_1',slot_town_population,10000),
			(party_set_slot,'p_city_1',slot_town_population_max,100000),
			(party_set_slot,'p_city_1',slot_town_population_growth_factor,1),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_city_1',slot_town_demand_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_city_1',slot_town_storehouse_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_city_1',slot_town_facility_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_city_1',slot_town_surplus_array,'$return'),

			(party_set_slot,'p_city_2',slot_town_center,0),
			(party_set_slot,'p_city_2',slot_town_castle,0),
			(party_set_slot,'p_city_2',slot_town_inn,0),
			(party_set_slot,'p_city_2',slot_town_store,0),
			(party_set_slot,'p_city_2',slot_town_smithy,0),
			(party_set_slot,'p_city_2',slot_town_capital,south_kyoto),
			(party_set_slot,'p_city_2',slot_town_dojo,0),
			(party_set_slot,'p_city_2',slot_town_sensei,-1),
			(party_set_slot,'p_city_2',slot_town_kokujin,'trp_city_2_kokujin'),
			(party_set_slot,'p_city_2',slot_town_shugo,-1),
			(party_set_slot,'p_city_2',slot_town_innkeeper,'trp_city_2_innkeeper'),
			(party_set_slot,'p_city_2',slot_town_weaponsmith,'trp_city_2_weaponsmith'),
			(party_set_slot,'p_city_2',slot_town_armorer,'trp_city_2_armorer'),
			(party_set_slot,'p_city_2',slot_town_merchant,'trp_city_2_merchant'),
			(party_set_slot,'p_city_2',slot_town_broker,null),
			(party_set_slot,'p_city_2',slot_town_moneychanger,'trp_moneychanger_2'),
			(party_set_slot,'p_city_2',slot_town_fishmonger,'trp_city_2_fishmonger'),
			(party_set_slot,'p_city_2',slot_town_horse_trader,null),
			(party_set_slot,'p_city_2',slot_town_export_good,itm_kyoto_sake),
			(party_set_slot,'p_city_2',slot_town_export_rate,100),
			(party_set_slot,'p_city_2',slot_town_import_good,itm_salt),
			(party_set_slot,'p_city_2',slot_town_import_rate,100),
			(party_set_slot,'p_city_2',slot_town_terrain,ter_highland),
			(party_set_slot,'p_city_2',slot_town_size,ct_city),
			(party_set_slot,'p_city_2',slot_town_mercs,'p_city_2_mercs'),
			(party_set_slot,'p_city_2',slot_town_trade_hub,1),
			(party_set_slot,'p_city_2',slot_town_trade_dest,-1),
			(party_set_slot,'p_city_2',slot_town_trade_month,-1),
			(party_set_slot,'p_city_2',slot_town_att_to_player,att_cautious),
			(party_set_slot,'p_city_2',slot_town_player_relation,0),
			(party_set_slot,'p_city_2',slot_town_import_demand,3),
			(party_set_slot,'p_city_2',slot_town_export_demand,3),
			(party_set_slot,'p_city_2',slot_town_demand,0),
			(call_script,'script_town_init_trade_dest','p_city_2',null,null,null,null,null,null),
			(party_set_slot,'p_city_2',slot_town_treasury,36000),
			(party_set_slot,'p_city_2',slot_town_garrison_source,'p_city_garrison_source'),
			(party_set_slot,'p_city_2',slot_town_siege_active,0),
			(party_set_slot,'p_city_2',slot_town_under_siege,false),
			(party_set_slot,'p_city_2',slot_town_is_besieged_by,null),
			(party_set_slot,'p_city_2',slot_town_initial_faction,0),
			(party_set_slot,'p_city_2',slot_town_scene_flags,0),
			(party_set_slot,'p_city_2',slot_town_reserve_patrol,-1),
			(party_set_slot,'p_city_2',slot_town_spawn_points,10000),
			(party_set_slot,'p_city_2',slot_party_type,spt_city),
			(party_set_slot,'p_city_2',slot_party_food,100000),
			(party_set_slot,'p_city_2',slot_party_icon,'icon_town'),
			(party_set_slot,'p_city_2',slot_party_icon_state,tis_normal),
			(party_set_slot,'p_city_2',slot_party_ai_state,null),
			(party_set_slot,'p_city_2',slot_party_ai_object,null),
			(party_set_slot,'p_city_2',slot_town_accumulated_rents,0),
			(party_set_slot,'p_city_2',slot_town_accumulated_tariffs,0),
			(party_set_slot,'p_city_2',slot_town_current_improvement,null),
			(party_set_slot,'p_city_2',slot_town_improvement_end_hour,null),
			(party_set_slot,'p_city_2',slot_town_housing_level,1),
			(party_set_slot,'p_city_2',slot_town_irrigation_level,1),
			(party_set_slot,'p_city_2',slot_town_mill_level,1),
			(party_set_slot,'p_city_2',slot_town_raided_by,null),
			(party_set_slot,'p_city_2',slot_town_state,sts_normal),
			(party_set_slot,'p_city_2',slot_town_raid_progress,null),
			(party_set_slot,'p_city_2',slot_town_recover_progress,null),
			(party_set_slot,'p_city_2',slot_town_production_bonus,1),
			(party_set_slot,'p_city_2',slot_town_siege_days,0),
			(party_set_slot,'p_city_2',slot_town_reserve_patrol,null),
			(party_set_slot,'p_city_2',slot_town_trade_good_productions_begin,null),
			(party_set_slot,'p_city_2',slot_town_trade_good_temp_productions_begin,null),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_city_2',slot_town_trade_good_price_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_city_2',slot_town_trade_good_abundance_array,'$return'),
			(party_set_slot,'p_city_2',slot_town_tax_rate,100),
			(party_set_slot,'p_city_2',slot_town_shoen,null),
			(party_set_slot,'p_city_2',slot_town_prefecture_array,null),
			(party_set_slot,'p_city_2',slot_town_reinforcements_a,'pt_city_reinforcements_a'),
			(party_set_slot,'p_city_2',slot_town_reinforcements_b,'pt_city_reinforcements_b'),
			(party_set_slot,'p_city_2',slot_town_reinforcements_c,'pt_city_reinforcements_c'),
			(party_set_slot,'p_city_2',slot_town_population,10000),
			(party_set_slot,'p_city_2',slot_town_population_max,100000),
			(party_set_slot,'p_city_2',slot_town_population_growth_factor,1),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_city_2',slot_town_demand_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_city_2',slot_town_storehouse_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_city_2',slot_town_facility_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_city_2',slot_town_surplus_array,'$return'),

			(party_set_slot,'p_city_3',slot_town_center,0),
			(party_set_slot,'p_city_3',slot_town_castle,0),
			(party_set_slot,'p_city_3',slot_town_inn,0),
			(party_set_slot,'p_city_3',slot_town_store,0),
			(party_set_slot,'p_city_3',slot_town_smithy,0),
			(party_set_slot,'p_city_3',slot_town_capital,south_kyoto),
			(party_set_slot,'p_city_3',slot_town_dojo,0),
			(party_set_slot,'p_city_3',slot_town_sensei,-1),
			(party_set_slot,'p_city_3',slot_town_kokujin,'trp_city_3_kokujin'),
			(party_set_slot,'p_city_3',slot_town_shugo,-1),
			(party_set_slot,'p_city_3',slot_town_innkeeper,'trp_city_3_innkeeper'),
			(party_set_slot,'p_city_3',slot_town_weaponsmith,'trp_city_3_weaponsmith'),
			(party_set_slot,'p_city_3',slot_town_armorer,'trp_city_3_armorer'),
			(party_set_slot,'p_city_3',slot_town_merchant,'trp_city_3_merchant'),
			(party_set_slot,'p_city_3',slot_town_broker,null),
			(party_set_slot,'p_city_3',slot_town_moneychanger,'trp_moneychanger_3'),
			(party_set_slot,'p_city_3',slot_town_fishmonger,'trp_city_3_fishmonger'),
			(party_set_slot,'p_city_3',slot_town_horse_trader,null),
			(party_set_slot,'p_city_3',slot_town_export_good,itm_kyoto_sake),
			(party_set_slot,'p_city_3',slot_town_export_rate,100),
			(party_set_slot,'p_city_3',slot_town_import_good,itm_salt),
			(party_set_slot,'p_city_3',slot_town_import_rate,100),
			(party_set_slot,'p_city_3',slot_town_terrain,ter_highland),
			(party_set_slot,'p_city_3',slot_town_size,ct_city),
			(party_set_slot,'p_city_3',slot_town_mercs,'p_city_3_mercs'),
			(party_set_slot,'p_city_3',slot_town_trade_hub,1),
			(party_set_slot,'p_city_3',slot_town_trade_dest,-1),
			(party_set_slot,'p_city_3',slot_town_trade_month,-1),
			(party_set_slot,'p_city_3',slot_town_att_to_player,att_cautious),
			(party_set_slot,'p_city_3',slot_town_player_relation,0),
			(party_set_slot,'p_city_3',slot_town_import_demand,3),
			(party_set_slot,'p_city_3',slot_town_export_demand,3),
			(party_set_slot,'p_city_3',slot_town_demand,0),
			(call_script,'script_town_init_trade_dest','p_city_3',null,null,null,null,null,null),
			(party_set_slot,'p_city_3',slot_town_treasury,36000),
			(party_set_slot,'p_city_3',slot_town_garrison_source,'p_city_garrison_source'),
			(party_set_slot,'p_city_3',slot_town_siege_active,0),
			(party_set_slot,'p_city_3',slot_town_under_siege,false),
			(party_set_slot,'p_city_3',slot_town_is_besieged_by,null),
			(party_set_slot,'p_city_3',slot_town_initial_faction,0),
			(party_set_slot,'p_city_3',slot_town_scene_flags,0),
			(party_set_slot,'p_city_3',slot_town_reserve_patrol,-1),
			(party_set_slot,'p_city_3',slot_town_spawn_points,10000),
			(party_set_slot,'p_city_3',slot_party_type,spt_city),
			(party_set_slot,'p_city_3',slot_party_food,100000),
			(party_set_slot,'p_city_3',slot_party_icon,'icon_town'),
			(party_set_slot,'p_city_3',slot_party_icon_state,tis_normal),
			(party_set_slot,'p_city_3',slot_party_ai_state,null),
			(party_set_slot,'p_city_3',slot_party_ai_object,null),
			(party_set_slot,'p_city_3',slot_town_accumulated_rents,0),
			(party_set_slot,'p_city_3',slot_town_accumulated_tariffs,0),
			(party_set_slot,'p_city_3',slot_town_current_improvement,null),
			(party_set_slot,'p_city_3',slot_town_improvement_end_hour,null),
			(party_set_slot,'p_city_3',slot_town_housing_level,1),
			(party_set_slot,'p_city_3',slot_town_irrigation_level,1),
			(party_set_slot,'p_city_3',slot_town_mill_level,1),
			(party_set_slot,'p_city_3',slot_town_raided_by,null),
			(party_set_slot,'p_city_3',slot_town_state,sts_normal),
			(party_set_slot,'p_city_3',slot_town_raid_progress,null),
			(party_set_slot,'p_city_3',slot_town_recover_progress,null),
			(party_set_slot,'p_city_3',slot_town_production_bonus,1),
			(party_set_slot,'p_city_3',slot_town_siege_days,0),
			(party_set_slot,'p_city_3',slot_town_reserve_patrol,null),
			(party_set_slot,'p_city_3',slot_town_trade_good_productions_begin,null),
			(party_set_slot,'p_city_3',slot_town_trade_good_temp_productions_begin,null),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_city_3',slot_town_trade_good_price_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_city_3',slot_town_trade_good_abundance_array,'$return'),
			(party_set_slot,'p_city_3',slot_town_tax_rate,100),
			(party_set_slot,'p_city_3',slot_town_shoen,null),
			(party_set_slot,'p_city_3',slot_town_prefecture_array,null),
			(party_set_slot,'p_city_3',slot_town_reinforcements_a,'pt_city_reinforcements_a'),
			(party_set_slot,'p_city_3',slot_town_reinforcements_b,'pt_city_reinforcements_b'),
			(party_set_slot,'p_city_3',slot_town_reinforcements_c,'pt_city_reinforcements_c'),
			(party_set_slot,'p_city_3',slot_town_population,10000),
			(party_set_slot,'p_city_3',slot_town_population_max,100000),
			(party_set_slot,'p_city_3',slot_town_population_growth_factor,1),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_city_3',slot_town_demand_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_city_3',slot_town_storehouse_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_city_3',slot_town_facility_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_city_3',slot_town_surplus_array,'$return'),

			(party_set_slot,'p_city_4',slot_town_center,0),
			(party_set_slot,'p_city_4',slot_town_castle,0),
			(party_set_slot,'p_city_4',slot_town_inn,0),
			(party_set_slot,'p_city_4',slot_town_store,0),
			(party_set_slot,'p_city_4',slot_town_smithy,0),
			(party_set_slot,'p_city_4',slot_town_capital,south_kyoto),
			(party_set_slot,'p_city_4',slot_town_dojo,0),
			(party_set_slot,'p_city_4',slot_town_sensei,-1),
			(party_set_slot,'p_city_4',slot_town_kokujin,'trp_city_4_kokujin'),
			(party_set_slot,'p_city_4',slot_town_shugo,-1),
			(party_set_slot,'p_city_4',slot_town_innkeeper,'trp_city_4_innkeeper'),
			(party_set_slot,'p_city_4',slot_town_weaponsmith,'trp_city_4_weaponsmith'),
			(party_set_slot,'p_city_4',slot_town_armorer,'trp_city_4_armorer'),
			(party_set_slot,'p_city_4',slot_town_merchant,'trp_city_4_merchant'),
			(party_set_slot,'p_city_4',slot_town_broker,null),
			(party_set_slot,'p_city_4',slot_town_moneychanger,'trp_moneychanger_4'),
			(party_set_slot,'p_city_4',slot_town_fishmonger,'trp_city_4_fishmonger'),
			(party_set_slot,'p_city_4',slot_town_horse_trader,null),
			(party_set_slot,'p_city_4',slot_town_export_good,itm_kyoto_sake),
			(party_set_slot,'p_city_4',slot_town_export_rate,100),
			(party_set_slot,'p_city_4',slot_town_import_good,itm_salt),
			(party_set_slot,'p_city_4',slot_town_import_rate,100),
			(party_set_slot,'p_city_4',slot_town_terrain,ter_highland),
			(party_set_slot,'p_city_4',slot_town_size,ct_city),
			(party_set_slot,'p_city_4',slot_town_mercs,'p_city_4_mercs'),
			(party_set_slot,'p_city_4',slot_town_trade_hub,1),
			(party_set_slot,'p_city_4',slot_town_trade_dest,-1),
			(party_set_slot,'p_city_4',slot_town_trade_month,-1),
			(party_set_slot,'p_city_4',slot_town_att_to_player,att_cautious),
			(party_set_slot,'p_city_4',slot_town_player_relation,0),
			(party_set_slot,'p_city_4',slot_town_import_demand,3),
			(party_set_slot,'p_city_4',slot_town_export_demand,3),
			(party_set_slot,'p_city_4',slot_town_demand,0),
			(call_script,'script_town_init_trade_dest','p_city_4',null,null,null,null,null,null),
			(party_set_slot,'p_city_4',slot_town_treasury,36000),
			(party_set_slot,'p_city_4',slot_town_garrison_source,'p_city_garrison_source'),
			(party_set_slot,'p_city_4',slot_town_siege_active,0),
			(party_set_slot,'p_city_4',slot_town_under_siege,false),
			(party_set_slot,'p_city_4',slot_town_is_besieged_by,null),
			(party_set_slot,'p_city_4',slot_town_initial_faction,0),
			(party_set_slot,'p_city_4',slot_town_scene_flags,0),
			(party_set_slot,'p_city_4',slot_town_reserve_patrol,-1),
			(party_set_slot,'p_city_4',slot_town_spawn_points,10000),
			(party_set_slot,'p_city_4',slot_party_type,spt_city),
			(party_set_slot,'p_city_4',slot_party_food,100000),
			(party_set_slot,'p_city_4',slot_party_icon,'icon_town'),
			(party_set_slot,'p_city_4',slot_party_icon_state,tis_normal),
			(party_set_slot,'p_city_4',slot_party_ai_state,null),
			(party_set_slot,'p_city_4',slot_party_ai_object,null),
			(party_set_slot,'p_city_4',slot_town_accumulated_rents,0),
			(party_set_slot,'p_city_4',slot_town_accumulated_tariffs,0),
			(party_set_slot,'p_city_4',slot_town_current_improvement,null),
			(party_set_slot,'p_city_4',slot_town_improvement_end_hour,null),
			(party_set_slot,'p_city_4',slot_town_housing_level,1),
			(party_set_slot,'p_city_4',slot_town_irrigation_level,1),
			(party_set_slot,'p_city_4',slot_town_mill_level,1),
			(party_set_slot,'p_city_4',slot_town_raided_by,null),
			(party_set_slot,'p_city_4',slot_town_state,sts_normal),
			(party_set_slot,'p_city_4',slot_town_raid_progress,null),
			(party_set_slot,'p_city_4',slot_town_recover_progress,null),
			(party_set_slot,'p_city_4',slot_town_production_bonus,1),
			(party_set_slot,'p_city_4',slot_town_siege_days,0),
			(party_set_slot,'p_city_4',slot_town_reserve_patrol,null),
			(party_set_slot,'p_city_4',slot_town_trade_good_productions_begin,null),
			(party_set_slot,'p_city_4',slot_town_trade_good_temp_productions_begin,null),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_city_4',slot_town_trade_good_price_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_city_4',slot_town_trade_good_abundance_array,'$return'),
			(party_set_slot,'p_city_4',slot_town_tax_rate,100),
			(party_set_slot,'p_city_4',slot_town_shoen,null),
			(party_set_slot,'p_city_4',slot_town_prefecture_array,null),
			(party_set_slot,'p_city_4',slot_town_reinforcements_a,'pt_city_reinforcements_a'),
			(party_set_slot,'p_city_4',slot_town_reinforcements_b,'pt_city_reinforcements_b'),
			(party_set_slot,'p_city_4',slot_town_reinforcements_c,'pt_city_reinforcements_c'),
			(party_set_slot,'p_city_4',slot_town_population,10000),
			(party_set_slot,'p_city_4',slot_town_population_max,100000),
			(party_set_slot,'p_city_4',slot_town_population_growth_factor,1),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_city_4',slot_town_demand_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_city_4',slot_town_storehouse_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_city_4',slot_town_facility_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_city_4',slot_town_surplus_array,'$return'),

			(party_set_slot,'p_city_5',slot_town_center,0),
			(party_set_slot,'p_city_5',slot_town_castle,0),
			(party_set_slot,'p_city_5',slot_town_inn,0),
			(party_set_slot,'p_city_5',slot_town_store,0),
			(party_set_slot,'p_city_5',slot_town_smithy,0),
			(party_set_slot,'p_city_5',slot_town_capital,hyogo),
			(party_set_slot,'p_city_5',slot_town_dojo,0),
			(party_set_slot,'p_city_5',slot_town_sensei,-1),
			(party_set_slot,'p_city_5',slot_town_kokujin,'trp_city_5_kokujin'),
			(party_set_slot,'p_city_5',slot_town_shugo,-1),
			(party_set_slot,'p_city_5',slot_town_innkeeper,'trp_city_5_innkeeper'),
			(party_set_slot,'p_city_5',slot_town_weaponsmith,'trp_city_5_weaponsmith'),
			(party_set_slot,'p_city_5',slot_town_armorer,'trp_city_5_armorer'),
			(party_set_slot,'p_city_5',slot_town_merchant,'trp_city_5_merchant'),
			(party_set_slot,'p_city_5',slot_town_broker,'trp_broker_1'),
			(party_set_slot,'p_city_5',slot_town_moneychanger,'trp_moneychanger_5'),
			(party_set_slot,'p_city_5',slot_town_fishmonger,'trp_city_5_fishmonger'),
			(party_set_slot,'p_city_5',slot_town_horse_trader,null),
			(party_set_slot,'p_city_5',slot_town_export_good,itm_kyoto_sake),
			(party_set_slot,'p_city_5',slot_town_export_rate,100),
			(party_set_slot,'p_city_5',slot_town_import_good,itm_salt),
			(party_set_slot,'p_city_5',slot_town_import_rate,100),
			(party_set_slot,'p_city_5',slot_town_terrain,ter_seaside),
			(party_set_slot,'p_city_5',slot_town_size,ct_city),
			(party_set_slot,'p_city_5',slot_town_mercs,'p_city_5_mercs'),
			(party_set_slot,'p_city_5',slot_town_trade_hub,1),
			(party_set_slot,'p_city_5',slot_town_trade_dest,-1),
			(party_set_slot,'p_city_5',slot_town_trade_month,-1),
			(party_set_slot,'p_city_5',slot_town_att_to_player,att_cautious),
			(party_set_slot,'p_city_5',slot_town_player_relation,0),
			(party_set_slot,'p_city_5',slot_town_import_demand,3),
			(party_set_slot,'p_city_5',slot_town_export_demand,3),
			(party_set_slot,'p_city_5',slot_town_demand,0),
			(call_script,'script_town_init_trade_dest','p_city_5',takase,himeji,kameyama,null,null,null),
			(party_set_slot,'p_city_5',slot_town_treasury,36000),
			(party_set_slot,'p_city_5',slot_town_garrison_source,'p_city_garrison_source'),
			(party_set_slot,'p_city_5',slot_town_siege_active,0),
			(party_set_slot,'p_city_5',slot_town_under_siege,false),
			(party_set_slot,'p_city_5',slot_town_is_besieged_by,null),
			(party_set_slot,'p_city_5',slot_town_initial_faction,0),
			(party_set_slot,'p_city_5',slot_town_scene_flags,0),
			(party_set_slot,'p_city_5',slot_town_reserve_patrol,-1),
			(party_set_slot,'p_city_5',slot_town_spawn_points,10000),
			(party_set_slot,'p_city_5',slot_party_type,spt_city),
			(party_set_slot,'p_city_5',slot_party_food,100000),
			(party_set_slot,'p_city_5',slot_party_icon,'icon_town'),
			(party_set_slot,'p_city_5',slot_party_icon_state,tis_normal),
			(party_set_slot,'p_city_5',slot_party_ai_state,null),
			(party_set_slot,'p_city_5',slot_party_ai_object,null),
			(party_set_slot,'p_city_5',slot_town_accumulated_rents,0),
			(party_set_slot,'p_city_5',slot_town_accumulated_tariffs,0),
			(party_set_slot,'p_city_5',slot_town_current_improvement,null),
			(party_set_slot,'p_city_5',slot_town_improvement_end_hour,null),
			(party_set_slot,'p_city_5',slot_town_housing_level,1),
			(party_set_slot,'p_city_5',slot_town_irrigation_level,1),
			(party_set_slot,'p_city_5',slot_town_mill_level,1),
			(party_set_slot,'p_city_5',slot_town_raided_by,null),
			(party_set_slot,'p_city_5',slot_town_state,sts_normal),
			(party_set_slot,'p_city_5',slot_town_raid_progress,null),
			(party_set_slot,'p_city_5',slot_town_recover_progress,null),
			(party_set_slot,'p_city_5',slot_town_production_bonus,1),
			(party_set_slot,'p_city_5',slot_town_siege_days,0),
			(party_set_slot,'p_city_5',slot_town_reserve_patrol,null),
			(party_set_slot,'p_city_5',slot_town_trade_good_productions_begin,null),
			(party_set_slot,'p_city_5',slot_town_trade_good_temp_productions_begin,null),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_city_5',slot_town_trade_good_price_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_city_5',slot_town_trade_good_abundance_array,'$return'),
			(party_set_slot,'p_city_5',slot_town_tax_rate,100),
			(party_set_slot,'p_city_5',slot_town_shoen,null),
			(party_set_slot,'p_city_5',slot_town_prefecture_array,null),
			(party_set_slot,'p_city_5',slot_town_reinforcements_a,'pt_city_reinforcements_a'),
			(party_set_slot,'p_city_5',slot_town_reinforcements_b,'pt_city_reinforcements_b'),
			(party_set_slot,'p_city_5',slot_town_reinforcements_c,'pt_city_reinforcements_c'),
			(party_set_slot,'p_city_5',slot_town_population,10000),
			(party_set_slot,'p_city_5',slot_town_population_max,100000),
			(party_set_slot,'p_city_5',slot_town_population_growth_factor,1),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_city_5',slot_town_demand_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_city_5',slot_town_storehouse_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_city_5',slot_town_facility_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_city_5',slot_town_surplus_array,'$return'),

			(party_set_slot,'p_city_6',slot_town_center,0),
			(party_set_slot,'p_city_6',slot_town_castle,0),
			(party_set_slot,'p_city_6',slot_town_inn,0),
			(party_set_slot,'p_city_6',slot_town_store,0),
			(party_set_slot,'p_city_6',slot_town_smithy,0),
			(party_set_slot,'p_city_6',slot_town_capital,himeji),
			(party_set_slot,'p_city_6',slot_town_dojo,0),
			(party_set_slot,'p_city_6',slot_town_sensei,-1),
			(party_set_slot,'p_city_6',slot_town_kokujin,'trp_city_6_kokujin'),
			(party_set_slot,'p_city_6',slot_town_shugo,'trp_himeji_shugo'),
			(party_set_slot,'p_city_6',slot_town_innkeeper,'trp_city_6_innkeeper'),
			(party_set_slot,'p_city_6',slot_town_weaponsmith,'trp_city_6_weaponsmith'),
			(party_set_slot,'p_city_6',slot_town_armorer,'trp_city_6_armorer'),
			(party_set_slot,'p_city_6',slot_town_merchant,'trp_city_6_merchant'),
			(party_set_slot,'p_city_6',slot_town_broker,'trp_broker_2'),
			(party_set_slot,'p_city_6',slot_town_moneychanger,'trp_moneychanger_6'),
			(party_set_slot,'p_city_6',slot_town_fishmonger,'trp_city_6_fishmonger'),
			(party_set_slot,'p_city_6',slot_town_horse_trader,null),
			(party_set_slot,'p_city_6',slot_town_export_good,itm_kyoto_sake),
			(party_set_slot,'p_city_6',slot_town_export_rate,100),
			(party_set_slot,'p_city_6',slot_town_import_good,itm_salt),
			(party_set_slot,'p_city_6',slot_town_import_rate,100),
			(party_set_slot,'p_city_6',slot_town_terrain,ter_seaside),
			(party_set_slot,'p_city_6',slot_town_size,ct_city),
			(party_set_slot,'p_city_6',slot_town_mercs,'p_city_6_mercs'),
			(party_set_slot,'p_city_6',slot_town_trade_hub,1),
			(party_set_slot,'p_city_6',slot_town_trade_dest,-1),
			(party_set_slot,'p_city_6',slot_town_trade_month,-1),
			(party_set_slot,'p_city_6',slot_town_att_to_player,att_cautious),
			(party_set_slot,'p_city_6',slot_town_player_relation,0),
			(party_set_slot,'p_city_6',slot_town_import_demand,3),
			(party_set_slot,'p_city_6',slot_town_export_demand,3),
			(party_set_slot,'p_city_6',slot_town_demand,0),
			(call_script,'script_town_init_trade_dest','p_city_6',hyogo,miyazu,null,null,null,null),
			(party_set_slot,'p_city_6',slot_town_treasury,36000),
			(party_set_slot,'p_city_6',slot_town_garrison_source,'p_city_garrison_source'),
			(party_set_slot,'p_city_6',slot_town_siege_active,0),
			(party_set_slot,'p_city_6',slot_town_under_siege,false),
			(party_set_slot,'p_city_6',slot_town_is_besieged_by,null),
			(party_set_slot,'p_city_6',slot_town_initial_faction,0),
			(party_set_slot,'p_city_6',slot_town_scene_flags,0),
			(party_set_slot,'p_city_6',slot_town_reserve_patrol,-1),
			(party_set_slot,'p_city_6',slot_town_spawn_points,10000),
			(party_set_slot,'p_city_6',slot_party_type,spt_city),
			(party_set_slot,'p_city_6',slot_party_food,100000),
			(party_set_slot,'p_city_6',slot_party_icon,'icon_town'),
			(party_set_slot,'p_city_6',slot_party_icon_state,tis_normal),
			(party_set_slot,'p_city_6',slot_party_ai_state,null),
			(party_set_slot,'p_city_6',slot_party_ai_object,null),
			(party_set_slot,'p_city_6',slot_town_accumulated_rents,0),
			(party_set_slot,'p_city_6',slot_town_accumulated_tariffs,0),
			(party_set_slot,'p_city_6',slot_town_current_improvement,null),
			(party_set_slot,'p_city_6',slot_town_improvement_end_hour,null),
			(party_set_slot,'p_city_6',slot_town_housing_level,1),
			(party_set_slot,'p_city_6',slot_town_irrigation_level,1),
			(party_set_slot,'p_city_6',slot_town_mill_level,1),
			(party_set_slot,'p_city_6',slot_town_raided_by,null),
			(party_set_slot,'p_city_6',slot_town_state,sts_normal),
			(party_set_slot,'p_city_6',slot_town_raid_progress,null),
			(party_set_slot,'p_city_6',slot_town_recover_progress,null),
			(party_set_slot,'p_city_6',slot_town_production_bonus,1),
			(party_set_slot,'p_city_6',slot_town_siege_days,0),
			(party_set_slot,'p_city_6',slot_town_reserve_patrol,null),
			(party_set_slot,'p_city_6',slot_town_trade_good_productions_begin,null),
			(party_set_slot,'p_city_6',slot_town_trade_good_temp_productions_begin,null),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_city_6',slot_town_trade_good_price_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_city_6',slot_town_trade_good_abundance_array,'$return'),
			(party_set_slot,'p_city_6',slot_town_tax_rate,100),
			(party_set_slot,'p_city_6',slot_town_shoen,null),
			(party_set_slot,'p_city_6',slot_town_prefecture_array,null),
			(party_set_slot,'p_city_6',slot_town_reinforcements_a,'pt_city_reinforcements_a'),
			(party_set_slot,'p_city_6',slot_town_reinforcements_b,'pt_city_reinforcements_b'),
			(party_set_slot,'p_city_6',slot_town_reinforcements_c,'pt_city_reinforcements_c'),
			(party_set_slot,'p_city_6',slot_town_population,10000),
			(party_set_slot,'p_city_6',slot_town_population_max,100000),
			(party_set_slot,'p_city_6',slot_town_population_growth_factor,1),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_city_6',slot_town_demand_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_city_6',slot_town_storehouse_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_city_6',slot_town_facility_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_city_6',slot_town_surplus_array,'$return'),

			(party_set_slot,'p_city_7',slot_town_center,0),
			(party_set_slot,'p_city_7',slot_town_castle,0),
			(party_set_slot,'p_city_7',slot_town_inn,0),
			(party_set_slot,'p_city_7',slot_town_store,0),
			(party_set_slot,'p_city_7',slot_town_smithy,0),
			(party_set_slot,'p_city_7',slot_town_capital,obama),
			(party_set_slot,'p_city_7',slot_town_dojo,0),
			(party_set_slot,'p_city_7',slot_town_sensei,-1),
			(party_set_slot,'p_city_7',slot_town_kokujin,'trp_city_7_kokujin'),
			(party_set_slot,'p_city_7',slot_town_shugo,'trp_obama_shugo'),
			(party_set_slot,'p_city_7',slot_town_innkeeper,'trp_city_7_innkeeper'),
			(party_set_slot,'p_city_7',slot_town_weaponsmith,'trp_city_7_weaponsmith'),
			(party_set_slot,'p_city_7',slot_town_armorer,'trp_city_7_armorer'),
			(party_set_slot,'p_city_7',slot_town_merchant,'trp_city_7_merchant'),
			(party_set_slot,'p_city_7',slot_town_broker,'trp_broker_3'),
			(party_set_slot,'p_city_7',slot_town_moneychanger,'trp_moneychanger_7'),
			(party_set_slot,'p_city_7',slot_town_fishmonger,'trp_city_7_fishmonger'),
			(party_set_slot,'p_city_7',slot_town_horse_trader,null),
			(party_set_slot,'p_city_7',slot_town_export_good,itm_kyoto_sake),
			(party_set_slot,'p_city_7',slot_town_export_rate,100),
			(party_set_slot,'p_city_7',slot_town_import_good,itm_salt),
			(party_set_slot,'p_city_7',slot_town_import_rate,100),
			(party_set_slot,'p_city_7',slot_town_terrain,ter_seaside),
			(party_set_slot,'p_city_7',slot_town_size,ct_port),
			(party_set_slot,'p_city_7',slot_town_mercs,'p_city_7_mercs'),
			(party_set_slot,'p_city_7',slot_town_trade_hub,1),
			(party_set_slot,'p_city_7',slot_town_trade_dest,-1),
			(party_set_slot,'p_city_7',slot_town_trade_month,-1),
			(party_set_slot,'p_city_7',slot_town_att_to_player,att_cautious),
			(party_set_slot,'p_city_7',slot_town_player_relation,0),
			(party_set_slot,'p_city_7',slot_town_import_demand,3),
			(party_set_slot,'p_city_7',slot_town_export_demand,3),
			(party_set_slot,'p_city_7',slot_town_demand,0),
			(call_script,'script_town_init_trade_dest','p_city_7',kameyama,miyazu,null,null,null,null),
			(party_set_slot,'p_city_7',slot_town_treasury,36000),
			(party_set_slot,'p_city_7',slot_town_garrison_source,'p_city_garrison_source'),
			(party_set_slot,'p_city_7',slot_town_siege_active,0),
			(party_set_slot,'p_city_7',slot_town_under_siege,false),
			(party_set_slot,'p_city_7',slot_town_is_besieged_by,null),
			(party_set_slot,'p_city_7',slot_town_initial_faction,0),
			(party_set_slot,'p_city_7',slot_town_scene_flags,0),
			(party_set_slot,'p_city_7',slot_town_reserve_patrol,-1),
			(party_set_slot,'p_city_7',slot_town_spawn_points,10000),
			(party_set_slot,'p_city_7',slot_party_type,spt_city),
			(party_set_slot,'p_city_7',slot_party_food,100000),
			(party_set_slot,'p_city_7',slot_party_icon,'icon_town'),
			(party_set_slot,'p_city_7',slot_party_icon_state,tis_normal),
			(party_set_slot,'p_city_7',slot_party_ai_state,null),
			(party_set_slot,'p_city_7',slot_party_ai_object,null),
			(party_set_slot,'p_city_7',slot_town_accumulated_rents,0),
			(party_set_slot,'p_city_7',slot_town_accumulated_tariffs,0),
			(party_set_slot,'p_city_7',slot_town_current_improvement,null),
			(party_set_slot,'p_city_7',slot_town_improvement_end_hour,null),
			(party_set_slot,'p_city_7',slot_town_housing_level,1),
			(party_set_slot,'p_city_7',slot_town_irrigation_level,1),
			(party_set_slot,'p_city_7',slot_town_mill_level,1),
			(party_set_slot,'p_city_7',slot_town_raided_by,null),
			(party_set_slot,'p_city_7',slot_town_state,sts_normal),
			(party_set_slot,'p_city_7',slot_town_raid_progress,null),
			(party_set_slot,'p_city_7',slot_town_recover_progress,null),
			(party_set_slot,'p_city_7',slot_town_production_bonus,1),
			(party_set_slot,'p_city_7',slot_town_siege_days,0),
			(party_set_slot,'p_city_7',slot_town_reserve_patrol,null),
			(party_set_slot,'p_city_7',slot_town_trade_good_productions_begin,null),
			(party_set_slot,'p_city_7',slot_town_trade_good_temp_productions_begin,null),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_city_7',slot_town_trade_good_price_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_city_7',slot_town_trade_good_abundance_array,'$return'),
			(party_set_slot,'p_city_7',slot_town_tax_rate,100),
			(party_set_slot,'p_city_7',slot_town_shoen,null),
			(party_set_slot,'p_city_7',slot_town_prefecture_array,null),
			(party_set_slot,'p_city_7',slot_town_reinforcements_a,'pt_city_reinforcements_a'),
			(party_set_slot,'p_city_7',slot_town_reinforcements_b,'pt_city_reinforcements_b'),
			(party_set_slot,'p_city_7',slot_town_reinforcements_c,'pt_city_reinforcements_c'),
			(party_set_slot,'p_city_7',slot_town_population,10000),
			(party_set_slot,'p_city_7',slot_town_population_max,100000),
			(party_set_slot,'p_city_7',slot_town_population_growth_factor,1),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_city_7',slot_town_demand_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_city_7',slot_town_storehouse_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_city_7',slot_town_facility_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_city_7',slot_town_surplus_array,'$return'),

			(party_set_slot,'p_city_8',slot_town_center,0),
			(party_set_slot,'p_city_8',slot_town_castle,0),
			(party_set_slot,'p_city_8',slot_town_inn,0),
			(party_set_slot,'p_city_8',slot_town_store,0),
			(party_set_slot,'p_city_8',slot_town_smithy,0),
			(party_set_slot,'p_city_8',slot_town_capital,kakogawa),
			(party_set_slot,'p_city_8',slot_town_dojo,0),
			(party_set_slot,'p_city_8',slot_town_sensei,-1),
			(party_set_slot,'p_city_8',slot_town_kokujin,'trp_city_8_kokujin'),
			(party_set_slot,'p_city_8',slot_town_shugo,-1),
			(party_set_slot,'p_city_8',slot_town_innkeeper,'trp_city_8_innkeeper'),
			(party_set_slot,'p_city_8',slot_town_weaponsmith,'trp_city_8_weaponsmith'),
			(party_set_slot,'p_city_8',slot_town_armorer,'trp_city_8_armorer'),
			(party_set_slot,'p_city_8',slot_town_merchant,'trp_city_8_merchant'),
			(party_set_slot,'p_city_8',slot_town_broker,'trp_broker_4'),
			(party_set_slot,'p_city_8',slot_town_moneychanger,'trp_moneychanger_8'),
			(party_set_slot,'p_city_8',slot_town_fishmonger,'trp_city_8_fishmonger'),
			(party_set_slot,'p_city_8',slot_town_horse_trader,null),
			(party_set_slot,'p_city_8',slot_town_export_good,itm_kyoto_sake),
			(party_set_slot,'p_city_8',slot_town_export_rate,100),
			(party_set_slot,'p_city_8',slot_town_import_good,itm_salt),
			(party_set_slot,'p_city_8',slot_town_import_rate,100),
			(party_set_slot,'p_city_8',slot_town_terrain,ter_lowland),
			(party_set_slot,'p_city_8',slot_town_size,ct_city),
			(party_set_slot,'p_city_8',slot_town_mercs,'p_city_8_mercs'),
			(party_set_slot,'p_city_8',slot_town_trade_hub,1),
			(party_set_slot,'p_city_8',slot_town_trade_dest,-1),
			(party_set_slot,'p_city_8',slot_town_trade_month,-1),
			(party_set_slot,'p_city_8',slot_town_att_to_player,att_cautious),
			(party_set_slot,'p_city_8',slot_town_player_relation,0),
			(party_set_slot,'p_city_8',slot_town_import_demand,3),
			(party_set_slot,'p_city_8',slot_town_export_demand,3),
			(party_set_slot,'p_city_8',slot_town_demand,0),
			(call_script,'script_town_init_trade_dest','p_city_8',himeji,null,null,null,null,null),
			(party_set_slot,'p_city_8',slot_town_treasury,36000),
			(party_set_slot,'p_city_8',slot_town_garrison_source,'p_city_garrison_source'),
			(party_set_slot,'p_city_8',slot_town_siege_active,0),
			(party_set_slot,'p_city_8',slot_town_under_siege,false),
			(party_set_slot,'p_city_8',slot_town_is_besieged_by,null),
			(party_set_slot,'p_city_8',slot_town_initial_faction,0),
			(party_set_slot,'p_city_8',slot_town_scene_flags,0),
			(party_set_slot,'p_city_8',slot_town_reserve_patrol,-1),
			(party_set_slot,'p_city_8',slot_town_spawn_points,10000),
			(party_set_slot,'p_city_8',slot_party_type,spt_city),
			(party_set_slot,'p_city_8',slot_party_food,100000),
			(party_set_slot,'p_city_8',slot_party_icon,'icon_town'),
			(party_set_slot,'p_city_8',slot_party_icon_state,tis_normal),
			(party_set_slot,'p_city_8',slot_party_ai_state,null),
			(party_set_slot,'p_city_8',slot_party_ai_object,null),
			(party_set_slot,'p_city_8',slot_town_accumulated_rents,0),
			(party_set_slot,'p_city_8',slot_town_accumulated_tariffs,0),
			(party_set_slot,'p_city_8',slot_town_current_improvement,null),
			(party_set_slot,'p_city_8',slot_town_improvement_end_hour,null),
			(party_set_slot,'p_city_8',slot_town_housing_level,1),
			(party_set_slot,'p_city_8',slot_town_irrigation_level,1),
			(party_set_slot,'p_city_8',slot_town_mill_level,1),
			(party_set_slot,'p_city_8',slot_town_raided_by,null),
			(party_set_slot,'p_city_8',slot_town_state,sts_normal),
			(party_set_slot,'p_city_8',slot_town_raid_progress,null),
			(party_set_slot,'p_city_8',slot_town_recover_progress,null),
			(party_set_slot,'p_city_8',slot_town_production_bonus,1),
			(party_set_slot,'p_city_8',slot_town_siege_days,0),
			(party_set_slot,'p_city_8',slot_town_reserve_patrol,null),
			(party_set_slot,'p_city_8',slot_town_trade_good_productions_begin,null),
			(party_set_slot,'p_city_8',slot_town_trade_good_temp_productions_begin,null),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_city_8',slot_town_trade_good_price_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_city_8',slot_town_trade_good_abundance_array,'$return'),
			(party_set_slot,'p_city_8',slot_town_tax_rate,100),
			(party_set_slot,'p_city_8',slot_town_shoen,null),
			(party_set_slot,'p_city_8',slot_town_prefecture_array,null),
			(party_set_slot,'p_city_8',slot_town_reinforcements_a,'pt_city_reinforcements_a'),
			(party_set_slot,'p_city_8',slot_town_reinforcements_b,'pt_city_reinforcements_b'),
			(party_set_slot,'p_city_8',slot_town_reinforcements_c,'pt_city_reinforcements_c'),
			(party_set_slot,'p_city_8',slot_town_population,10000),
			(party_set_slot,'p_city_8',slot_town_population_max,100000),
			(party_set_slot,'p_city_8',slot_town_population_growth_factor,1),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_city_8',slot_town_demand_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_city_8',slot_town_storehouse_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_city_8',slot_town_facility_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_city_8',slot_town_surplus_array,'$return'),

			(party_set_slot,'p_city_9',slot_town_center,0),
			(party_set_slot,'p_city_9',slot_town_castle,0),
			(party_set_slot,'p_city_9',slot_town_inn,0),
			(party_set_slot,'p_city_9',slot_town_store,0),
			(party_set_slot,'p_city_9',slot_town_smithy,0),
			(party_set_slot,'p_city_9',slot_town_capital,south_kyoto),
			(party_set_slot,'p_city_9',slot_town_dojo,0),
			(party_set_slot,'p_city_9',slot_town_sensei,-1),
			(party_set_slot,'p_city_9',slot_town_kokujin,'trp_city_9_kokujin'),
			(party_set_slot,'p_city_9',slot_town_shugo,'trp_otsu_shugo'),
			(party_set_slot,'p_city_9',slot_town_innkeeper,'trp_city_9_innkeeper'),
			(party_set_slot,'p_city_9',slot_town_weaponsmith,'trp_city_9_weaponsmith'),
			(party_set_slot,'p_city_9',slot_town_armorer,'trp_city_9_armorer'),
			(party_set_slot,'p_city_9',slot_town_merchant,'trp_city_9_merchant'),
			(party_set_slot,'p_city_9',slot_town_broker,null),
			(party_set_slot,'p_city_9',slot_town_moneychanger,'trp_moneychanger_9'),
			(party_set_slot,'p_city_9',slot_town_fishmonger,'trp_city_9_fishmonger'),
			(party_set_slot,'p_city_9',slot_town_horse_trader,null),
			(party_set_slot,'p_city_9',slot_town_export_good,itm_kyoto_sake),
			(party_set_slot,'p_city_9',slot_town_export_rate,100),
			(party_set_slot,'p_city_9',slot_town_import_good,itm_salt),
			(party_set_slot,'p_city_9',slot_town_import_rate,100),
			(party_set_slot,'p_city_9',slot_town_terrain,ter_lakeside),
			(party_set_slot,'p_city_9',slot_town_size,ct_city),
			(party_set_slot,'p_city_9',slot_town_mercs,'p_city_9_mercs'),
			(party_set_slot,'p_city_9',slot_town_trade_hub,1),
			(party_set_slot,'p_city_9',slot_town_trade_dest,-1),
			(party_set_slot,'p_city_9',slot_town_trade_month,-1),
			(party_set_slot,'p_city_9',slot_town_att_to_player,att_cautious),
			(party_set_slot,'p_city_9',slot_town_player_relation,0),
			(party_set_slot,'p_city_9',slot_town_import_demand,3),
			(party_set_slot,'p_city_9',slot_town_export_demand,3),
			(party_set_slot,'p_city_9',slot_town_demand,0),
			(call_script,'script_town_init_trade_dest','p_city_9',sakai,south_kyoto,fujidera,null,null,null),
			(party_set_slot,'p_city_9',slot_town_treasury,36000),
			(party_set_slot,'p_city_9',slot_town_garrison_source,'p_city_garrison_source'),
			(party_set_slot,'p_city_9',slot_town_siege_active,0),
			(party_set_slot,'p_city_9',slot_town_under_siege,false),
			(party_set_slot,'p_city_9',slot_town_is_besieged_by,null),
			(party_set_slot,'p_city_9',slot_town_initial_faction,0),
			(party_set_slot,'p_city_9',slot_town_scene_flags,0),
			(party_set_slot,'p_city_9',slot_town_reserve_patrol,-1),
			(party_set_slot,'p_city_9',slot_town_spawn_points,10000),
			(party_set_slot,'p_city_9',slot_party_type,spt_city),
			(party_set_slot,'p_city_9',slot_party_food,100000),
			(party_set_slot,'p_city_9',slot_party_icon,'icon_town'),
			(party_set_slot,'p_city_9',slot_party_icon_state,tis_normal),
			(party_set_slot,'p_city_9',slot_party_ai_state,null),
			(party_set_slot,'p_city_9',slot_party_ai_object,null),
			(party_set_slot,'p_city_9',slot_town_accumulated_rents,0),
			(party_set_slot,'p_city_9',slot_town_accumulated_tariffs,0),
			(party_set_slot,'p_city_9',slot_town_current_improvement,null),
			(party_set_slot,'p_city_9',slot_town_improvement_end_hour,null),
			(party_set_slot,'p_city_9',slot_town_housing_level,1),
			(party_set_slot,'p_city_9',slot_town_irrigation_level,1),
			(party_set_slot,'p_city_9',slot_town_mill_level,1),
			(party_set_slot,'p_city_9',slot_town_raided_by,null),
			(party_set_slot,'p_city_9',slot_town_state,sts_normal),
			(party_set_slot,'p_city_9',slot_town_raid_progress,null),
			(party_set_slot,'p_city_9',slot_town_recover_progress,null),
			(party_set_slot,'p_city_9',slot_town_production_bonus,1),
			(party_set_slot,'p_city_9',slot_town_siege_days,0),
			(party_set_slot,'p_city_9',slot_town_reserve_patrol,null),
			(party_set_slot,'p_city_9',slot_town_trade_good_productions_begin,null),
			(party_set_slot,'p_city_9',slot_town_trade_good_temp_productions_begin,null),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_city_9',slot_town_trade_good_price_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_city_9',slot_town_trade_good_abundance_array,'$return'),
			(party_set_slot,'p_city_9',slot_town_tax_rate,100),
			(party_set_slot,'p_city_9',slot_town_shoen,null),
			(party_set_slot,'p_city_9',slot_town_prefecture_array,null),
			(party_set_slot,'p_city_9',slot_town_reinforcements_a,'pt_city_reinforcements_a'),
			(party_set_slot,'p_city_9',slot_town_reinforcements_b,'pt_city_reinforcements_b'),
			(party_set_slot,'p_city_9',slot_town_reinforcements_c,'pt_city_reinforcements_c'),
			(party_set_slot,'p_city_9',slot_town_population,10000),
			(party_set_slot,'p_city_9',slot_town_population_max,100000),
			(party_set_slot,'p_city_9',slot_town_population_growth_factor,1),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_city_9',slot_town_demand_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_city_9',slot_town_storehouse_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_city_9',slot_town_facility_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_city_9',slot_town_surplus_array,'$return'),

			(party_set_slot,'p_city_10',slot_town_center,0),
			(party_set_slot,'p_city_10',slot_town_castle,0),
			(party_set_slot,'p_city_10',slot_town_inn,0),
			(party_set_slot,'p_city_10',slot_town_store,0),
			(party_set_slot,'p_city_10',slot_town_smithy,0),
			(party_set_slot,'p_city_10',slot_town_capital,sakai),
			(party_set_slot,'p_city_10',slot_town_dojo,0),
			(party_set_slot,'p_city_10',slot_town_sensei,-1),
			(party_set_slot,'p_city_10',slot_town_kokujin,'trp_city_10_kokujin'),
			(party_set_slot,'p_city_10',slot_town_shugo,'trp_sakai_shugo'),
			(party_set_slot,'p_city_10',slot_town_innkeeper,'trp_city_10_innkeeper'),
			(party_set_slot,'p_city_10',slot_town_weaponsmith,'trp_city_10_weaponsmith'),
			(party_set_slot,'p_city_10',slot_town_armorer,'trp_city_10_armorer'),
			(party_set_slot,'p_city_10',slot_town_merchant,'trp_city_10_merchant'),
			(party_set_slot,'p_city_10',slot_town_broker,'trp_broker_6'),
			(party_set_slot,'p_city_10',slot_town_moneychanger,'trp_moneychanger_10'),
			(party_set_slot,'p_city_10',slot_town_fishmonger,'trp_city_10_fishmonger'),
			(party_set_slot,'p_city_10',slot_town_horse_trader,null),
			(party_set_slot,'p_city_10',slot_town_export_good,itm_kyoto_sake),
			(party_set_slot,'p_city_10',slot_town_export_rate,100),
			(party_set_slot,'p_city_10',slot_town_import_good,itm_salt),
			(party_set_slot,'p_city_10',slot_town_import_rate,100),
			(party_set_slot,'p_city_10',slot_town_terrain,ter_seaside),
			(party_set_slot,'p_city_10',slot_town_size,ct_port),
			(party_set_slot,'p_city_10',slot_town_mercs,'p_city_10_mercs'),
			(party_set_slot,'p_city_10',slot_town_trade_hub,1),
			(party_set_slot,'p_city_10',slot_town_trade_dest,-1),
			(party_set_slot,'p_city_10',slot_town_trade_month,-1),
			(party_set_slot,'p_city_10',slot_town_att_to_player,att_cautious),
			(party_set_slot,'p_city_10',slot_town_player_relation,0),
			(party_set_slot,'p_city_10',slot_town_import_demand,3),
			(party_set_slot,'p_city_10',slot_town_export_demand,3),
			(party_set_slot,'p_city_10',slot_town_demand,0),
			(call_script,'script_town_init_trade_dest','p_city_10',wakayama,south_kyoto,null,null,null,null),
			(party_set_slot,'p_city_10',slot_town_treasury,36000),
			(party_set_slot,'p_city_10',slot_town_garrison_source,'p_city_garrison_source'),
			(party_set_slot,'p_city_10',slot_town_siege_active,0),
			(party_set_slot,'p_city_10',slot_town_under_siege,false),
			(party_set_slot,'p_city_10',slot_town_is_besieged_by,null),
			(party_set_slot,'p_city_10',slot_town_initial_faction,0),
			(party_set_slot,'p_city_10',slot_town_scene_flags,0),
			(party_set_slot,'p_city_10',slot_town_reserve_patrol,-1),
			(party_set_slot,'p_city_10',slot_town_spawn_points,10000),
			(party_set_slot,'p_city_10',slot_party_type,spt_city),
			(party_set_slot,'p_city_10',slot_party_food,100000),
			(party_set_slot,'p_city_10',slot_party_icon,'icon_town'),
			(party_set_slot,'p_city_10',slot_party_icon_state,tis_normal),
			(party_set_slot,'p_city_10',slot_party_ai_state,null),
			(party_set_slot,'p_city_10',slot_party_ai_object,null),
			(party_set_slot,'p_city_10',slot_town_accumulated_rents,0),
			(party_set_slot,'p_city_10',slot_town_accumulated_tariffs,0),
			(party_set_slot,'p_city_10',slot_town_current_improvement,null),
			(party_set_slot,'p_city_10',slot_town_improvement_end_hour,null),
			(party_set_slot,'p_city_10',slot_town_housing_level,1),
			(party_set_slot,'p_city_10',slot_town_irrigation_level,1),
			(party_set_slot,'p_city_10',slot_town_mill_level,1),
			(party_set_slot,'p_city_10',slot_town_raided_by,null),
			(party_set_slot,'p_city_10',slot_town_state,sts_normal),
			(party_set_slot,'p_city_10',slot_town_raid_progress,null),
			(party_set_slot,'p_city_10',slot_town_recover_progress,null),
			(party_set_slot,'p_city_10',slot_town_production_bonus,1),
			(party_set_slot,'p_city_10',slot_town_siege_days,0),
			(party_set_slot,'p_city_10',slot_town_reserve_patrol,null),
			(party_set_slot,'p_city_10',slot_town_trade_good_productions_begin,null),
			(party_set_slot,'p_city_10',slot_town_trade_good_temp_productions_begin,null),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_city_10',slot_town_trade_good_price_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_city_10',slot_town_trade_good_abundance_array,'$return'),
			(party_set_slot,'p_city_10',slot_town_tax_rate,100),
			(party_set_slot,'p_city_10',slot_town_shoen,null),
			(party_set_slot,'p_city_10',slot_town_prefecture_array,null),
			(party_set_slot,'p_city_10',slot_town_reinforcements_a,'pt_city_reinforcements_a'),
			(party_set_slot,'p_city_10',slot_town_reinforcements_b,'pt_city_reinforcements_b'),
			(party_set_slot,'p_city_10',slot_town_reinforcements_c,'pt_city_reinforcements_c'),
			(party_set_slot,'p_city_10',slot_town_population,10000),
			(party_set_slot,'p_city_10',slot_town_population_max,100000),
			(party_set_slot,'p_city_10',slot_town_population_growth_factor,1),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_city_10',slot_town_demand_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_city_10',slot_town_storehouse_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_city_10',slot_town_facility_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_city_10',slot_town_surplus_array,'$return'),

			(party_set_slot,'p_city_11',slot_town_center,0),
			(party_set_slot,'p_city_11',slot_town_castle,0),
			(party_set_slot,'p_city_11',slot_town_inn,0),
			(party_set_slot,'p_city_11',slot_town_store,0),
			(party_set_slot,'p_city_11',slot_town_smithy,0),
			(party_set_slot,'p_city_11',slot_town_capital,wakayama),
			(party_set_slot,'p_city_11',slot_town_dojo,0),
			(party_set_slot,'p_city_11',slot_town_sensei,-1),
			(party_set_slot,'p_city_11',slot_town_kokujin,'trp_city_11_kokujin'),
			(party_set_slot,'p_city_11',slot_town_shugo,'trp_wakayama_shugo'),
			(party_set_slot,'p_city_11',slot_town_innkeeper,'trp_city_11_innkeeper'),
			(party_set_slot,'p_city_11',slot_town_weaponsmith,'trp_city_11_weaponsmith'),
			(party_set_slot,'p_city_11',slot_town_armorer,'trp_city_11_armorer'),
			(party_set_slot,'p_city_11',slot_town_merchant,'trp_city_11_merchant'),
			(party_set_slot,'p_city_11',slot_town_broker,'trp_broker_7'),
			(party_set_slot,'p_city_11',slot_town_moneychanger,'trp_moneychanger_11'),
			(party_set_slot,'p_city_11',slot_town_fishmonger,'trp_city_11_fishmonger'),
			(party_set_slot,'p_city_11',slot_town_horse_trader,null),
			(party_set_slot,'p_city_11',slot_town_export_good,itm_kyoto_sake),
			(party_set_slot,'p_city_11',slot_town_export_rate,100),
			(party_set_slot,'p_city_11',slot_town_import_good,itm_salt),
			(party_set_slot,'p_city_11',slot_town_import_rate,100),
			(party_set_slot,'p_city_11',slot_town_terrain,ter_seaside),
			(party_set_slot,'p_city_11',slot_town_size,ct_port),
			(party_set_slot,'p_city_11',slot_town_mercs,'p_city_11_mercs'),
			(party_set_slot,'p_city_11',slot_town_trade_hub,1),
			(party_set_slot,'p_city_11',slot_town_trade_dest,-1),
			(party_set_slot,'p_city_11',slot_town_trade_month,-1),
			(party_set_slot,'p_city_11',slot_town_att_to_player,att_cautious),
			(party_set_slot,'p_city_11',slot_town_player_relation,0),
			(party_set_slot,'p_city_11',slot_town_import_demand,3),
			(party_set_slot,'p_city_11',slot_town_export_demand,3),
			(party_set_slot,'p_city_11',slot_town_demand,0),
			(call_script,'script_town_init_trade_dest','p_city_11',nara,fujidera,null,null,null,null),
			(party_set_slot,'p_city_11',slot_town_treasury,36000),
			(party_set_slot,'p_city_11',slot_town_garrison_source,'p_city_garrison_source'),
			(party_set_slot,'p_city_11',slot_town_siege_active,0),
			(party_set_slot,'p_city_11',slot_town_under_siege,false),
			(party_set_slot,'p_city_11',slot_town_is_besieged_by,null),
			(party_set_slot,'p_city_11',slot_town_initial_faction,0),
			(party_set_slot,'p_city_11',slot_town_scene_flags,0),
			(party_set_slot,'p_city_11',slot_town_reserve_patrol,-1),
			(party_set_slot,'p_city_11',slot_town_spawn_points,10000),
			(party_set_slot,'p_city_11',slot_party_type,spt_city),
			(party_set_slot,'p_city_11',slot_party_food,100000),
			(party_set_slot,'p_city_11',slot_party_icon,'icon_town'),
			(party_set_slot,'p_city_11',slot_party_icon_state,tis_normal),
			(party_set_slot,'p_city_11',slot_party_ai_state,null),
			(party_set_slot,'p_city_11',slot_party_ai_object,null),
			(party_set_slot,'p_city_11',slot_town_accumulated_rents,0),
			(party_set_slot,'p_city_11',slot_town_accumulated_tariffs,0),
			(party_set_slot,'p_city_11',slot_town_current_improvement,null),
			(party_set_slot,'p_city_11',slot_town_improvement_end_hour,null),
			(party_set_slot,'p_city_11',slot_town_housing_level,1),
			(party_set_slot,'p_city_11',slot_town_irrigation_level,1),
			(party_set_slot,'p_city_11',slot_town_mill_level,1),
			(party_set_slot,'p_city_11',slot_town_raided_by,null),
			(party_set_slot,'p_city_11',slot_town_state,sts_normal),
			(party_set_slot,'p_city_11',slot_town_raid_progress,null),
			(party_set_slot,'p_city_11',slot_town_recover_progress,null),
			(party_set_slot,'p_city_11',slot_town_production_bonus,1),
			(party_set_slot,'p_city_11',slot_town_siege_days,0),
			(party_set_slot,'p_city_11',slot_town_reserve_patrol,null),
			(party_set_slot,'p_city_11',slot_town_trade_good_productions_begin,null),
			(party_set_slot,'p_city_11',slot_town_trade_good_temp_productions_begin,null),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_city_11',slot_town_trade_good_price_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_city_11',slot_town_trade_good_abundance_array,'$return'),
			(party_set_slot,'p_city_11',slot_town_tax_rate,100),
			(party_set_slot,'p_city_11',slot_town_shoen,null),
			(party_set_slot,'p_city_11',slot_town_prefecture_array,null),
			(party_set_slot,'p_city_11',slot_town_reinforcements_a,'pt_city_reinforcements_a'),
			(party_set_slot,'p_city_11',slot_town_reinforcements_b,'pt_city_reinforcements_b'),
			(party_set_slot,'p_city_11',slot_town_reinforcements_c,'pt_city_reinforcements_c'),
			(party_set_slot,'p_city_11',slot_town_population,10000),
			(party_set_slot,'p_city_11',slot_town_population_max,100000),
			(party_set_slot,'p_city_11',slot_town_population_growth_factor,1),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_city_11',slot_town_demand_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_city_11',slot_town_storehouse_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_city_11',slot_town_facility_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_city_11',slot_town_surplus_array,'$return'),

			(party_set_slot,'p_city_12',slot_town_center,0),
			(party_set_slot,'p_city_12',slot_town_castle,0),
			(party_set_slot,'p_city_12',slot_town_inn,0),
			(party_set_slot,'p_city_12',slot_town_store,0),
			(party_set_slot,'p_city_12',slot_town_smithy,0),
			(party_set_slot,'p_city_12',slot_town_capital,nara),
			(party_set_slot,'p_city_12',slot_town_dojo,0),
			(party_set_slot,'p_city_12',slot_town_sensei,-1),
			(party_set_slot,'p_city_12',slot_town_kokujin,'trp_city_12_kokujin'),
			(party_set_slot,'p_city_12',slot_town_shugo,'trp_nara_shugo'),
			(party_set_slot,'p_city_12',slot_town_innkeeper,'trp_city_12_innkeeper'),
			(party_set_slot,'p_city_12',slot_town_weaponsmith,'trp_city_12_weaponsmith'),
			(party_set_slot,'p_city_12',slot_town_armorer,'trp_city_12_armorer'),
			(party_set_slot,'p_city_12',slot_town_merchant,'trp_city_12_merchant'),
			(party_set_slot,'p_city_12',slot_town_broker,'trp_broker_8'),
			(party_set_slot,'p_city_12',slot_town_moneychanger,'trp_moneychanger_12'),
			(party_set_slot,'p_city_12',slot_town_fishmonger,'trp_city_12_fishmonger'),
			(party_set_slot,'p_city_12',slot_town_horse_trader,null),
			(party_set_slot,'p_city_12',slot_town_export_good,itm_kyoto_sake),
			(party_set_slot,'p_city_12',slot_town_export_rate,100),
			(party_set_slot,'p_city_12',slot_town_import_good,itm_salt),
			(party_set_slot,'p_city_12',slot_town_import_rate,100),
			(party_set_slot,'p_city_12',slot_town_terrain,ter_highland),
			(party_set_slot,'p_city_12',slot_town_size,ct_city),
			(party_set_slot,'p_city_12',slot_town_mercs,'p_city_12_mercs'),
			(party_set_slot,'p_city_12',slot_town_trade_hub,1),
			(party_set_slot,'p_city_12',slot_town_trade_dest,-1),
			(party_set_slot,'p_city_12',slot_town_trade_month,-1),
			(party_set_slot,'p_city_12',slot_town_att_to_player,att_cautious),
			(party_set_slot,'p_city_12',slot_town_player_relation,0),
			(party_set_slot,'p_city_12',slot_town_import_demand,3),
			(party_set_slot,'p_city_12',slot_town_export_demand,3),
			(party_set_slot,'p_city_12',slot_town_demand,0),
			(call_script,'script_town_init_trade_dest','p_city_12',south_kyoto,wakayama,fujidera,null,null,null),
			(party_set_slot,'p_city_12',slot_town_treasury,36000),
			(party_set_slot,'p_city_12',slot_town_garrison_source,'p_city_garrison_source'),
			(party_set_slot,'p_city_12',slot_town_siege_active,0),
			(party_set_slot,'p_city_12',slot_town_under_siege,false),
			(party_set_slot,'p_city_12',slot_town_is_besieged_by,null),
			(party_set_slot,'p_city_12',slot_town_initial_faction,0),
			(party_set_slot,'p_city_12',slot_town_scene_flags,0),
			(party_set_slot,'p_city_12',slot_town_reserve_patrol,-1),
			(party_set_slot,'p_city_12',slot_town_spawn_points,10000),
			(party_set_slot,'p_city_12',slot_party_type,spt_city),
			(party_set_slot,'p_city_12',slot_party_food,100000),
			(party_set_slot,'p_city_12',slot_party_icon,'icon_town'),
			(party_set_slot,'p_city_12',slot_party_icon_state,tis_normal),
			(party_set_slot,'p_city_12',slot_party_ai_state,null),
			(party_set_slot,'p_city_12',slot_party_ai_object,null),
			(party_set_slot,'p_city_12',slot_town_accumulated_rents,0),
			(party_set_slot,'p_city_12',slot_town_accumulated_tariffs,0),
			(party_set_slot,'p_city_12',slot_town_current_improvement,null),
			(party_set_slot,'p_city_12',slot_town_improvement_end_hour,null),
			(party_set_slot,'p_city_12',slot_town_housing_level,1),
			(party_set_slot,'p_city_12',slot_town_irrigation_level,1),
			(party_set_slot,'p_city_12',slot_town_mill_level,1),
			(party_set_slot,'p_city_12',slot_town_raided_by,null),
			(party_set_slot,'p_city_12',slot_town_state,sts_normal),
			(party_set_slot,'p_city_12',slot_town_raid_progress,null),
			(party_set_slot,'p_city_12',slot_town_recover_progress,null),
			(party_set_slot,'p_city_12',slot_town_production_bonus,1),
			(party_set_slot,'p_city_12',slot_town_siege_days,0),
			(party_set_slot,'p_city_12',slot_town_reserve_patrol,null),
			(party_set_slot,'p_city_12',slot_town_trade_good_productions_begin,null),
			(party_set_slot,'p_city_12',slot_town_trade_good_temp_productions_begin,null),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_city_12',slot_town_trade_good_price_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_city_12',slot_town_trade_good_abundance_array,'$return'),
			(party_set_slot,'p_city_12',slot_town_tax_rate,100),
			(party_set_slot,'p_city_12',slot_town_shoen,null),
			(party_set_slot,'p_city_12',slot_town_prefecture_array,null),
			(party_set_slot,'p_city_12',slot_town_reinforcements_a,'pt_city_reinforcements_a'),
			(party_set_slot,'p_city_12',slot_town_reinforcements_b,'pt_city_reinforcements_b'),
			(party_set_slot,'p_city_12',slot_town_reinforcements_c,'pt_city_reinforcements_c'),
			(party_set_slot,'p_city_12',slot_town_population,10000),
			(party_set_slot,'p_city_12',slot_town_population_max,100000),
			(party_set_slot,'p_city_12',slot_town_population_growth_factor,1),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_city_12',slot_town_demand_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_city_12',slot_town_storehouse_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_city_12',slot_town_facility_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_city_12',slot_town_surplus_array,'$return'),

			(party_set_slot,'p_city_13',slot_town_center,0),
			(party_set_slot,'p_city_13',slot_town_castle,0),
			(party_set_slot,'p_city_13',slot_town_inn,0),
			(party_set_slot,'p_city_13',slot_town_store,0),
			(party_set_slot,'p_city_13',slot_town_smithy,0),
			(party_set_slot,'p_city_13',slot_town_capital,nara),
			(party_set_slot,'p_city_13',slot_town_dojo,0),
			(party_set_slot,'p_city_13',slot_town_sensei,-1),
			(party_set_slot,'p_city_13',slot_town_kokujin,'trp_city_13_kokujin'),
			(party_set_slot,'p_city_13',slot_town_shugo,'trp_fujidera_shugo'),
			(party_set_slot,'p_city_13',slot_town_innkeeper,'trp_city_13_innkeeper'),
			(party_set_slot,'p_city_13',slot_town_weaponsmith,'trp_city_13_weaponsmith'),
			(party_set_slot,'p_city_13',slot_town_armorer,'trp_city_13_armorer'),
			(party_set_slot,'p_city_13',slot_town_merchant,'trp_city_13_merchant'),
			(party_set_slot,'p_city_13',slot_town_broker,null),
			(party_set_slot,'p_city_13',slot_town_moneychanger,'trp_moneychanger_13'),
			(party_set_slot,'p_city_13',slot_town_fishmonger,'trp_city_13_fishmonger'),
			(party_set_slot,'p_city_13',slot_town_horse_trader,null),
			(party_set_slot,'p_city_13',slot_town_export_good,itm_kyoto_sake),
			(party_set_slot,'p_city_13',slot_town_export_rate,100),
			(party_set_slot,'p_city_13',slot_town_import_good,itm_salt),
			(party_set_slot,'p_city_13',slot_town_import_rate,100),
			(party_set_slot,'p_city_13',slot_town_terrain,ter_lowland),
			(party_set_slot,'p_city_13',slot_town_size,ct_city),
			(party_set_slot,'p_city_13',slot_town_mercs,'p_city_13_mercs'),
			(party_set_slot,'p_city_13',slot_town_trade_hub,1),
			(party_set_slot,'p_city_13',slot_town_trade_dest,-1),
			(party_set_slot,'p_city_13',slot_town_trade_month,-1),
			(party_set_slot,'p_city_13',slot_town_att_to_player,att_cautious),
			(party_set_slot,'p_city_13',slot_town_player_relation,0),
			(party_set_slot,'p_city_13',slot_town_import_demand,3),
			(party_set_slot,'p_city_13',slot_town_export_demand,3),
			(party_set_slot,'p_city_13',slot_town_demand,0),
			(call_script,'script_town_init_trade_dest','p_city_13',south_kyoto,nara,null,null,null,null),
			(party_set_slot,'p_city_13',slot_town_treasury,36000),
			(party_set_slot,'p_city_13',slot_town_garrison_source,'p_city_garrison_source'),
			(party_set_slot,'p_city_13',slot_town_siege_active,0),
			(party_set_slot,'p_city_13',slot_town_under_siege,false),
			(party_set_slot,'p_city_13',slot_town_is_besieged_by,null),
			(party_set_slot,'p_city_13',slot_town_initial_faction,0),
			(party_set_slot,'p_city_13',slot_town_scene_flags,0),
			(party_set_slot,'p_city_13',slot_town_reserve_patrol,-1),
			(party_set_slot,'p_city_13',slot_town_spawn_points,10000),
			(party_set_slot,'p_city_13',slot_party_type,spt_city),
			(party_set_slot,'p_city_13',slot_party_food,100000),
			(party_set_slot,'p_city_13',slot_party_icon,'icon_town'),
			(party_set_slot,'p_city_13',slot_party_icon_state,tis_normal),
			(party_set_slot,'p_city_13',slot_party_ai_state,null),
			(party_set_slot,'p_city_13',slot_party_ai_object,null),
			(party_set_slot,'p_city_13',slot_town_accumulated_rents,0),
			(party_set_slot,'p_city_13',slot_town_accumulated_tariffs,0),
			(party_set_slot,'p_city_13',slot_town_current_improvement,null),
			(party_set_slot,'p_city_13',slot_town_improvement_end_hour,null),
			(party_set_slot,'p_city_13',slot_town_housing_level,1),
			(party_set_slot,'p_city_13',slot_town_irrigation_level,1),
			(party_set_slot,'p_city_13',slot_town_mill_level,1),
			(party_set_slot,'p_city_13',slot_town_raided_by,null),
			(party_set_slot,'p_city_13',slot_town_state,sts_normal),
			(party_set_slot,'p_city_13',slot_town_raid_progress,null),
			(party_set_slot,'p_city_13',slot_town_recover_progress,null),
			(party_set_slot,'p_city_13',slot_town_production_bonus,1),
			(party_set_slot,'p_city_13',slot_town_siege_days,0),
			(party_set_slot,'p_city_13',slot_town_reserve_patrol,null),
			(party_set_slot,'p_city_13',slot_town_trade_good_productions_begin,null),
			(party_set_slot,'p_city_13',slot_town_trade_good_temp_productions_begin,null),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_city_13',slot_town_trade_good_price_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_city_13',slot_town_trade_good_abundance_array,'$return'),
			(party_set_slot,'p_city_13',slot_town_tax_rate,100),
			(party_set_slot,'p_city_13',slot_town_shoen,null),
			(party_set_slot,'p_city_13',slot_town_prefecture_array,null),
			(party_set_slot,'p_city_13',slot_town_reinforcements_a,'pt_city_reinforcements_a'),
			(party_set_slot,'p_city_13',slot_town_reinforcements_b,'pt_city_reinforcements_b'),
			(party_set_slot,'p_city_13',slot_town_reinforcements_c,'pt_city_reinforcements_c'),
			(party_set_slot,'p_city_13',slot_town_population,10000),
			(party_set_slot,'p_city_13',slot_town_population_max,100000),
			(party_set_slot,'p_city_13',slot_town_population_growth_factor,1),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_city_13',slot_town_demand_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_city_13',slot_town_storehouse_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_city_13',slot_town_facility_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_city_13',slot_town_surplus_array,'$return'),

			(party_set_slot,'p_city_14',slot_town_center,0),
			(party_set_slot,'p_city_14',slot_town_castle,0),
			(party_set_slot,'p_city_14',slot_town_inn,0),
			(party_set_slot,'p_city_14',slot_town_store,0),
			(party_set_slot,'p_city_14',slot_town_smithy,0),
			(party_set_slot,'p_city_14',slot_town_capital,tsuruga),
			(party_set_slot,'p_city_14',slot_town_dojo,0),
			(party_set_slot,'p_city_14',slot_town_sensei,-1),
			(party_set_slot,'p_city_14',slot_town_kokujin,'trp_city_14_kokujin'),
			(party_set_slot,'p_city_14',slot_town_shugo,'trp_tsuruga_shugo'),
			(party_set_slot,'p_city_14',slot_town_innkeeper,'trp_city_14_innkeeper'),
			(party_set_slot,'p_city_14',slot_town_weaponsmith,'trp_city_14_weaponsmith'),
			(party_set_slot,'p_city_14',slot_town_armorer,'trp_city_14_armorer'),
			(party_set_slot,'p_city_14',slot_town_merchant,'trp_city_14_merchant'),
			(party_set_slot,'p_city_14',slot_town_broker,'trp_broker_10'),
			(party_set_slot,'p_city_14',slot_town_moneychanger,'trp_moneychanger_14'),
			(party_set_slot,'p_city_14',slot_town_fishmonger,'trp_city_14_fishmonger'),
			(party_set_slot,'p_city_14',slot_town_horse_trader,null),
			(party_set_slot,'p_city_14',slot_town_export_good,itm_kyoto_sake),
			(party_set_slot,'p_city_14',slot_town_export_rate,100),
			(party_set_slot,'p_city_14',slot_town_import_good,itm_salt),
			(party_set_slot,'p_city_14',slot_town_import_rate,100),
			(party_set_slot,'p_city_14',slot_town_terrain,ter_seaside),
			(party_set_slot,'p_city_14',slot_town_size,ct_port),
			(party_set_slot,'p_city_14',slot_town_mercs,'p_city_14_mercs'),
			(party_set_slot,'p_city_14',slot_town_trade_hub,1),
			(party_set_slot,'p_city_14',slot_town_trade_dest,-1),
			(party_set_slot,'p_city_14',slot_town_trade_month,-1),
			(party_set_slot,'p_city_14',slot_town_att_to_player,att_cautious),
			(party_set_slot,'p_city_14',slot_town_player_relation,0),
			(party_set_slot,'p_city_14',slot_town_import_demand,3),
			(party_set_slot,'p_city_14',slot_town_export_demand,3),
			(party_set_slot,'p_city_14',slot_town_demand,0),
			(call_script,'script_town_init_trade_dest','p_city_14',nara,null,null,null,null,null),
			(party_set_slot,'p_city_14',slot_town_treasury,36000),
			(party_set_slot,'p_city_14',slot_town_garrison_source,'p_city_garrison_source'),
			(party_set_slot,'p_city_14',slot_town_siege_active,0),
			(party_set_slot,'p_city_14',slot_town_under_siege,false),
			(party_set_slot,'p_city_14',slot_town_is_besieged_by,null),
			(party_set_slot,'p_city_14',slot_town_initial_faction,0),
			(party_set_slot,'p_city_14',slot_town_scene_flags,0),
			(party_set_slot,'p_city_14',slot_town_reserve_patrol,-1),
			(party_set_slot,'p_city_14',slot_town_spawn_points,10000),
			(party_set_slot,'p_city_14',slot_party_type,spt_city),
			(party_set_slot,'p_city_14',slot_party_food,100000),
			(party_set_slot,'p_city_14',slot_party_icon,'icon_town'),
			(party_set_slot,'p_city_14',slot_party_icon_state,tis_normal),
			(party_set_slot,'p_city_14',slot_party_ai_state,null),
			(party_set_slot,'p_city_14',slot_party_ai_object,null),
			(party_set_slot,'p_city_14',slot_town_accumulated_rents,0),
			(party_set_slot,'p_city_14',slot_town_accumulated_tariffs,0),
			(party_set_slot,'p_city_14',slot_town_current_improvement,null),
			(party_set_slot,'p_city_14',slot_town_improvement_end_hour,null),
			(party_set_slot,'p_city_14',slot_town_housing_level,1),
			(party_set_slot,'p_city_14',slot_town_irrigation_level,1),
			(party_set_slot,'p_city_14',slot_town_mill_level,1),
			(party_set_slot,'p_city_14',slot_town_raided_by,null),
			(party_set_slot,'p_city_14',slot_town_state,sts_normal),
			(party_set_slot,'p_city_14',slot_town_raid_progress,null),
			(party_set_slot,'p_city_14',slot_town_recover_progress,null),
			(party_set_slot,'p_city_14',slot_town_production_bonus,1),
			(party_set_slot,'p_city_14',slot_town_siege_days,0),
			(party_set_slot,'p_city_14',slot_town_reserve_patrol,null),
			(party_set_slot,'p_city_14',slot_town_trade_good_productions_begin,null),
			(party_set_slot,'p_city_14',slot_town_trade_good_temp_productions_begin,null),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_city_14',slot_town_trade_good_price_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_city_14',slot_town_trade_good_abundance_array,'$return'),
			(party_set_slot,'p_city_14',slot_town_tax_rate,100),
			(party_set_slot,'p_city_14',slot_town_shoen,null),
			(party_set_slot,'p_city_14',slot_town_prefecture_array,null),
			(party_set_slot,'p_city_14',slot_town_reinforcements_a,'pt_city_reinforcements_a'),
			(party_set_slot,'p_city_14',slot_town_reinforcements_b,'pt_city_reinforcements_b'),
			(party_set_slot,'p_city_14',slot_town_reinforcements_c,'pt_city_reinforcements_c'),
			(party_set_slot,'p_city_14',slot_town_population,10000),
			(party_set_slot,'p_city_14',slot_town_population_max,100000),
			(party_set_slot,'p_city_14',slot_town_population_growth_factor,1),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_city_14',slot_town_demand_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_city_14',slot_town_storehouse_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_city_14',slot_town_facility_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_city_14',slot_town_surplus_array,'$return'),

			(party_set_slot,'p_town_1',slot_town_center,0),
			(party_set_slot,'p_town_1',slot_town_castle,0),
			(party_set_slot,'p_town_1',slot_town_inn,0),
			(party_set_slot,'p_town_1',slot_town_store,0),
			(party_set_slot,'p_town_1',slot_town_smithy,0),
			(party_set_slot,'p_town_1',slot_town_capital,sakai),
			(party_set_slot,'p_town_1',slot_town_dojo,0),
			(party_set_slot,'p_town_1',slot_town_sensei,-1),
			(party_set_slot,'p_town_1',slot_town_kokujin,'trp_town_1_kokujin'),
			(party_set_slot,'p_town_1',slot_town_shugo,'trp_takase_shugo'),
			(party_set_slot,'p_town_1',slot_town_innkeeper,'trp_town_1_innkeeper'),
			(party_set_slot,'p_town_1',slot_town_weaponsmith,'trp_town_1_weaponsmith'),
			(party_set_slot,'p_town_1',slot_town_armorer,'trp_town_1_armorer'),
			(party_set_slot,'p_town_1',slot_town_merchant,'trp_town_1_merchant'),
			(party_set_slot,'p_town_1',slot_town_broker,'trp_broker_11'),
			(party_set_slot,'p_town_1',slot_town_moneychanger,null),
			(party_set_slot,'p_town_1',slot_town_fishmonger,'trp_town_1_fishmonger'),
			(party_set_slot,'p_town_1',slot_town_horse_trader,null),
			(party_set_slot,'p_town_1',slot_town_export_good,itm_kyoto_sake),
			(party_set_slot,'p_town_1',slot_town_export_rate,100),
			(party_set_slot,'p_town_1',slot_town_import_good,itm_salt),
			(party_set_slot,'p_town_1',slot_town_import_rate,100),
			(party_set_slot,'p_town_1',slot_town_terrain,ter_seaside),
			(party_set_slot,'p_town_1',slot_town_size,ct_port),
			(party_set_slot,'p_town_1',slot_town_mercs,'p_town_1_mercs'),
			(party_set_slot,'p_town_1',slot_town_trade_hub,1),
			(party_set_slot,'p_town_1',slot_town_trade_dest,-1),
			(party_set_slot,'p_town_1',slot_town_trade_month,4),
			(party_set_slot,'p_town_1',slot_town_att_to_player,att_cautious),
			(party_set_slot,'p_town_1',slot_town_player_relation,0),
			(party_set_slot,'p_town_1',slot_town_import_demand,3),
			(party_set_slot,'p_town_1',slot_town_export_demand,3),
			(party_set_slot,'p_town_1',slot_town_demand,0),
			(call_script,'script_town_init_trade_dest','p_town_1',hyogo,south_kyoto,kameyama,null,null,null),
			(party_set_slot,'p_town_1',slot_town_treasury,18000),
			(party_set_slot,'p_town_1',slot_town_garrison_source,'p_town_garrison_source'),
			(party_set_slot,'p_town_1',slot_town_siege_active,0),
			(party_set_slot,'p_town_1',slot_town_under_siege,false),
			(party_set_slot,'p_town_1',slot_town_is_besieged_by,null),
			(party_set_slot,'p_town_1',slot_town_initial_faction,0),
			(party_set_slot,'p_town_1',slot_town_scene_flags,0),
			(party_set_slot,'p_town_1',slot_town_reserve_patrol,-1),
			(party_set_slot,'p_town_1',slot_town_spawn_points,2500),
			(party_set_slot,'p_town_1',slot_party_type,spt_city),
			(party_set_slot,'p_town_1',slot_party_food,50000),
			(party_set_slot,'p_town_1',slot_party_icon,'icon_town'),
			(party_set_slot,'p_town_1',slot_party_icon_state,tis_normal),
			(party_set_slot,'p_town_1',slot_party_ai_state,null),
			(party_set_slot,'p_town_1',slot_party_ai_object,null),
			(party_set_slot,'p_town_1',slot_town_accumulated_rents,0),
			(party_set_slot,'p_town_1',slot_town_accumulated_tariffs,0),
			(party_set_slot,'p_town_1',slot_town_current_improvement,null),
			(party_set_slot,'p_town_1',slot_town_improvement_end_hour,null),
			(party_set_slot,'p_town_1',slot_town_housing_level,1),
			(party_set_slot,'p_town_1',slot_town_irrigation_level,1),
			(party_set_slot,'p_town_1',slot_town_mill_level,1),
			(party_set_slot,'p_town_1',slot_town_raided_by,null),
			(party_set_slot,'p_town_1',slot_town_state,sts_normal),
			(party_set_slot,'p_town_1',slot_town_raid_progress,null),
			(party_set_slot,'p_town_1',slot_town_recover_progress,null),
			(party_set_slot,'p_town_1',slot_town_production_bonus,1),
			(party_set_slot,'p_town_1',slot_town_siege_days,0),
			(party_set_slot,'p_town_1',slot_town_reserve_patrol,null),
			(party_set_slot,'p_town_1',slot_town_trade_good_productions_begin,null),
			(party_set_slot,'p_town_1',slot_town_trade_good_temp_productions_begin,null),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_town_1',slot_town_trade_good_price_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_town_1',slot_town_trade_good_abundance_array,'$return'),
			(party_set_slot,'p_town_1',slot_town_tax_rate,100),
			(party_set_slot,'p_town_1',slot_town_shoen,null),
			(party_set_slot,'p_town_1',slot_town_prefecture_array,null),
			(party_set_slot,'p_town_1',slot_town_reinforcements_a,'pt_town_reinforcements_a'),
			(party_set_slot,'p_town_1',slot_town_reinforcements_b,'pt_town_reinforcements_b'),
			(party_set_slot,'p_town_1',slot_town_reinforcements_c,'pt_town_reinforcements_c'),
			(party_set_slot,'p_town_1',slot_town_population,2500),
			(party_set_slot,'p_town_1',slot_town_population_max,10000),
			(party_set_slot,'p_town_1',slot_town_population_growth_factor,1),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_town_1',slot_town_demand_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_town_1',slot_town_storehouse_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_town_1',slot_town_facility_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_town_1',slot_town_surplus_array,'$return'),

			(party_set_slot,'p_town_2',slot_town_center,0),
			(party_set_slot,'p_town_2',slot_town_castle,0),
			(party_set_slot,'p_town_2',slot_town_inn,0),
			(party_set_slot,'p_town_2',slot_town_store,0),
			(party_set_slot,'p_town_2',slot_town_smithy,0),
			(party_set_slot,'p_town_2',slot_town_capital,kakogawa),
			(party_set_slot,'p_town_2',slot_town_dojo,0),
			(party_set_slot,'p_town_2',slot_town_sensei,-1),
			(party_set_slot,'p_town_2',slot_town_kokujin,'trp_town_2_kokujin'),
			(party_set_slot,'p_town_2',slot_town_shugo,-1),
			(party_set_slot,'p_town_2',slot_town_innkeeper,'trp_town_2_innkeeper'),
			(party_set_slot,'p_town_2',slot_town_weaponsmith,'trp_town_2_weaponsmith'),
			(party_set_slot,'p_town_2',slot_town_armorer,'trp_town_2_armorer'),
			(party_set_slot,'p_town_2',slot_town_merchant,'trp_town_2_merchant'),
			(party_set_slot,'p_town_2',slot_town_broker,null),
			(party_set_slot,'p_town_2',slot_town_moneychanger,null),
			(party_set_slot,'p_town_2',slot_town_fishmonger,'trp_town_2_fishmonger'),
			(party_set_slot,'p_town_2',slot_town_horse_trader,null),
			(party_set_slot,'p_town_2',slot_town_export_good,itm_kyoto_sake),
			(party_set_slot,'p_town_2',slot_town_export_rate,100),
			(party_set_slot,'p_town_2',slot_town_import_good,itm_salt),
			(party_set_slot,'p_town_2',slot_town_import_rate,100),
			(party_set_slot,'p_town_2',slot_town_terrain,ter_seaside),
			(party_set_slot,'p_town_2',slot_town_size,ct_large_town),
			(party_set_slot,'p_town_2',slot_town_mercs,'p_town_2_mercs'),
			(party_set_slot,'p_town_2',slot_town_trade_hub,2),
			(party_set_slot,'p_town_2',slot_town_trade_dest,-1),
			(party_set_slot,'p_town_2',slot_town_trade_month,7),
			(party_set_slot,'p_town_2',slot_town_att_to_player,att_cautious),
			(party_set_slot,'p_town_2',slot_town_player_relation,0),
			(party_set_slot,'p_town_2',slot_town_import_demand,3),
			(party_set_slot,'p_town_2',slot_town_export_demand,3),
			(party_set_slot,'p_town_2',slot_town_demand,0),
			(call_script,'script_town_init_trade_dest','p_town_2',null,null,null,null,null,null),
			(party_set_slot,'p_town_2',slot_town_treasury,18000),
			(party_set_slot,'p_town_2',slot_town_garrison_source,'p_town_garrison_source'),
			(party_set_slot,'p_town_2',slot_town_siege_active,0),
			(party_set_slot,'p_town_2',slot_town_under_siege,false),
			(party_set_slot,'p_town_2',slot_town_is_besieged_by,null),
			(party_set_slot,'p_town_2',slot_town_initial_faction,0),
			(party_set_slot,'p_town_2',slot_town_scene_flags,0),
			(party_set_slot,'p_town_2',slot_town_reserve_patrol,-1),
			(party_set_slot,'p_town_2',slot_town_spawn_points,2500),
			(party_set_slot,'p_town_2',slot_party_type,spt_city),
			(party_set_slot,'p_town_2',slot_party_food,50000),
			(party_set_slot,'p_town_2',slot_party_icon,'icon_town'),
			(party_set_slot,'p_town_2',slot_party_icon_state,tis_normal),
			(party_set_slot,'p_town_2',slot_party_ai_state,null),
			(party_set_slot,'p_town_2',slot_party_ai_object,null),
			(party_set_slot,'p_town_2',slot_town_accumulated_rents,0),
			(party_set_slot,'p_town_2',slot_town_accumulated_tariffs,0),
			(party_set_slot,'p_town_2',slot_town_current_improvement,null),
			(party_set_slot,'p_town_2',slot_town_improvement_end_hour,null),
			(party_set_slot,'p_town_2',slot_town_housing_level,1),
			(party_set_slot,'p_town_2',slot_town_irrigation_level,1),
			(party_set_slot,'p_town_2',slot_town_mill_level,1),
			(party_set_slot,'p_town_2',slot_town_raided_by,null),
			(party_set_slot,'p_town_2',slot_town_state,sts_normal),
			(party_set_slot,'p_town_2',slot_town_raid_progress,null),
			(party_set_slot,'p_town_2',slot_town_recover_progress,null),
			(party_set_slot,'p_town_2',slot_town_production_bonus,1),
			(party_set_slot,'p_town_2',slot_town_siege_days,0),
			(party_set_slot,'p_town_2',slot_town_reserve_patrol,null),
			(party_set_slot,'p_town_2',slot_town_trade_good_productions_begin,null),
			(party_set_slot,'p_town_2',slot_town_trade_good_temp_productions_begin,null),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_town_2',slot_town_trade_good_price_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_town_2',slot_town_trade_good_abundance_array,'$return'),
			(party_set_slot,'p_town_2',slot_town_tax_rate,100),
			(party_set_slot,'p_town_2',slot_town_shoen,null),
			(party_set_slot,'p_town_2',slot_town_prefecture_array,null),
			(party_set_slot,'p_town_2',slot_town_reinforcements_a,'pt_town_reinforcements_a'),
			(party_set_slot,'p_town_2',slot_town_reinforcements_b,'pt_town_reinforcements_b'),
			(party_set_slot,'p_town_2',slot_town_reinforcements_c,'pt_town_reinforcements_c'),
			(party_set_slot,'p_town_2',slot_town_population,2500),
			(party_set_slot,'p_town_2',slot_town_population_max,10000),
			(party_set_slot,'p_town_2',slot_town_population_growth_factor,1),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_town_2',slot_town_demand_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_town_2',slot_town_storehouse_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_town_2',slot_town_facility_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_town_2',slot_town_surplus_array,'$return'),

			(party_set_slot,'p_town_3',slot_town_center,0),
			(party_set_slot,'p_town_3',slot_town_castle,0),
			(party_set_slot,'p_town_3',slot_town_inn,0),
			(party_set_slot,'p_town_3',slot_town_store,0),
			(party_set_slot,'p_town_3',slot_town_smithy,0),
			(party_set_slot,'p_town_3',slot_town_capital,south_kyoto),
			(party_set_slot,'p_town_3',slot_town_dojo,0),
			(party_set_slot,'p_town_3',slot_town_sensei,-1),
			(party_set_slot,'p_town_3',slot_town_kokujin,'trp_town_3_kokujin'),
			(party_set_slot,'p_town_3',slot_town_shugo,-1),
			(party_set_slot,'p_town_3',slot_town_innkeeper,'trp_town_3_innkeeper'),
			(party_set_slot,'p_town_3',slot_town_weaponsmith,'trp_town_3_weaponsmith'),
			(party_set_slot,'p_town_3',slot_town_armorer,'trp_town_3_armorer'),
			(party_set_slot,'p_town_3',slot_town_merchant,'trp_town_3_merchant'),
			(party_set_slot,'p_town_3',slot_town_broker,null),
			(party_set_slot,'p_town_3',slot_town_moneychanger,null),
			(party_set_slot,'p_town_3',slot_town_fishmonger,'trp_town_3_fishmonger'),
			(party_set_slot,'p_town_3',slot_town_horse_trader,null),
			(party_set_slot,'p_town_3',slot_town_export_good,itm_kyoto_sake),
			(party_set_slot,'p_town_3',slot_town_export_rate,100),
			(party_set_slot,'p_town_3',slot_town_import_good,itm_salt),
			(party_set_slot,'p_town_3',slot_town_import_rate,100),
			(party_set_slot,'p_town_3',slot_town_terrain,ter_lowland),
			(party_set_slot,'p_town_3',slot_town_size,ct_large_town),
			(party_set_slot,'p_town_3',slot_town_mercs,'p_town_3_mercs'),
			(party_set_slot,'p_town_3',slot_town_trade_hub,0),
			(party_set_slot,'p_town_3',slot_town_trade_dest,south_kyoto),
			(party_set_slot,'p_town_3',slot_town_trade_month,10),
			(party_set_slot,'p_town_3',slot_town_att_to_player,att_cautious),
			(party_set_slot,'p_town_3',slot_town_player_relation,0),
			(party_set_slot,'p_town_3',slot_town_import_demand,3),
			(party_set_slot,'p_town_3',slot_town_export_demand,3),
			(party_set_slot,'p_town_3',slot_town_demand,0),
			(call_script,'script_town_init_trade_dest','p_town_3',null,null,null,null,null,null),
			(party_set_slot,'p_town_3',slot_town_treasury,18000),
			(party_set_slot,'p_town_3',slot_town_garrison_source,'p_town_garrison_source'),
			(party_set_slot,'p_town_3',slot_town_siege_active,0),
			(party_set_slot,'p_town_3',slot_town_under_siege,false),
			(party_set_slot,'p_town_3',slot_town_is_besieged_by,null),
			(party_set_slot,'p_town_3',slot_town_initial_faction,0),
			(party_set_slot,'p_town_3',slot_town_scene_flags,0),
			(party_set_slot,'p_town_3',slot_town_reserve_patrol,-1),
			(party_set_slot,'p_town_3',slot_town_spawn_points,2500),
			(party_set_slot,'p_town_3',slot_party_type,spt_city),
			(party_set_slot,'p_town_3',slot_party_food,50000),
			(party_set_slot,'p_town_3',slot_party_icon,'icon_town'),
			(party_set_slot,'p_town_3',slot_party_icon_state,tis_normal),
			(party_set_slot,'p_town_3',slot_party_ai_state,null),
			(party_set_slot,'p_town_3',slot_party_ai_object,null),
			(party_set_slot,'p_town_3',slot_town_accumulated_rents,0),
			(party_set_slot,'p_town_3',slot_town_accumulated_tariffs,0),
			(party_set_slot,'p_town_3',slot_town_current_improvement,null),
			(party_set_slot,'p_town_3',slot_town_improvement_end_hour,null),
			(party_set_slot,'p_town_3',slot_town_housing_level,1),
			(party_set_slot,'p_town_3',slot_town_irrigation_level,1),
			(party_set_slot,'p_town_3',slot_town_mill_level,1),
			(party_set_slot,'p_town_3',slot_town_raided_by,null),
			(party_set_slot,'p_town_3',slot_town_state,sts_normal),
			(party_set_slot,'p_town_3',slot_town_raid_progress,null),
			(party_set_slot,'p_town_3',slot_town_recover_progress,null),
			(party_set_slot,'p_town_3',slot_town_production_bonus,1),
			(party_set_slot,'p_town_3',slot_town_siege_days,0),
			(party_set_slot,'p_town_3',slot_town_reserve_patrol,null),
			(party_set_slot,'p_town_3',slot_town_trade_good_productions_begin,null),
			(party_set_slot,'p_town_3',slot_town_trade_good_temp_productions_begin,null),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_town_3',slot_town_trade_good_price_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_town_3',slot_town_trade_good_abundance_array,'$return'),
			(party_set_slot,'p_town_3',slot_town_tax_rate,100),
			(party_set_slot,'p_town_3',slot_town_shoen,null),
			(party_set_slot,'p_town_3',slot_town_prefecture_array,null),
			(party_set_slot,'p_town_3',slot_town_reinforcements_a,'pt_town_reinforcements_a'),
			(party_set_slot,'p_town_3',slot_town_reinforcements_b,'pt_town_reinforcements_b'),
			(party_set_slot,'p_town_3',slot_town_reinforcements_c,'pt_town_reinforcements_c'),
			(party_set_slot,'p_town_3',slot_town_population,2500),
			(party_set_slot,'p_town_3',slot_town_population_max,10000),
			(party_set_slot,'p_town_3',slot_town_population_growth_factor,1),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_town_3',slot_town_demand_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_town_3',slot_town_storehouse_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_town_3',slot_town_facility_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_town_3',slot_town_surplus_array,'$return'),

			(party_set_slot,'p_town_4',slot_town_center,0),
			(party_set_slot,'p_town_4',slot_town_castle,0),
			(party_set_slot,'p_town_4',slot_town_inn,0),
			(party_set_slot,'p_town_4',slot_town_store,0),
			(party_set_slot,'p_town_4',slot_town_smithy,0),
			(party_set_slot,'p_town_4',slot_town_capital,kameyama),
			(party_set_slot,'p_town_4',slot_town_dojo,0),
			(party_set_slot,'p_town_4',slot_town_sensei,-1),
			(party_set_slot,'p_town_4',slot_town_kokujin,'trp_town_4_kokujin'),
			(party_set_slot,'p_town_4',slot_town_shugo,'trp_kameyama_shugo'),
			(party_set_slot,'p_town_4',slot_town_innkeeper,'trp_town_4_innkeeper'),
			(party_set_slot,'p_town_4',slot_town_weaponsmith,'trp_town_4_weaponsmith'),
			(party_set_slot,'p_town_4',slot_town_armorer,'trp_town_4_armorer'),
			(party_set_slot,'p_town_4',slot_town_merchant,'trp_town_4_merchant'),
			(party_set_slot,'p_town_4',slot_town_broker,'trp_broker_12'),
			(party_set_slot,'p_town_4',slot_town_moneychanger,null),
			(party_set_slot,'p_town_4',slot_town_fishmonger,'trp_town_4_fishmonger'),
			(party_set_slot,'p_town_4',slot_town_horse_trader,null),
			(party_set_slot,'p_town_4',slot_town_export_good,itm_kyoto_sake),
			(party_set_slot,'p_town_4',slot_town_export_rate,100),
			(party_set_slot,'p_town_4',slot_town_import_good,itm_salt),
			(party_set_slot,'p_town_4',slot_town_import_rate,100),
			(party_set_slot,'p_town_4',slot_town_terrain,ter_low_valley),
			(party_set_slot,'p_town_4',slot_town_size,ct_large_town),
			(party_set_slot,'p_town_4',slot_town_mercs,'p_town_4_mercs'),
			(party_set_slot,'p_town_4',slot_town_trade_hub,1),
			(party_set_slot,'p_town_4',slot_town_trade_dest,-1),
			(party_set_slot,'p_town_4',slot_town_trade_month,4),
			(party_set_slot,'p_town_4',slot_town_att_to_player,att_cautious),
			(party_set_slot,'p_town_4',slot_town_player_relation,0),
			(party_set_slot,'p_town_4',slot_town_import_demand,3),
			(party_set_slot,'p_town_4',slot_town_export_demand,3),
			(party_set_slot,'p_town_4',slot_town_demand,0),
			(call_script,'script_town_init_trade_dest','p_town_4',south_kyoto,null,null,null,null,null),
			(party_set_slot,'p_town_4',slot_town_treasury,18000),
			(party_set_slot,'p_town_4',slot_town_garrison_source,'p_town_garrison_source'),
			(party_set_slot,'p_town_4',slot_town_siege_active,0),
			(party_set_slot,'p_town_4',slot_town_under_siege,false),
			(party_set_slot,'p_town_4',slot_town_is_besieged_by,null),
			(party_set_slot,'p_town_4',slot_town_initial_faction,0),
			(party_set_slot,'p_town_4',slot_town_scene_flags,0),
			(party_set_slot,'p_town_4',slot_town_reserve_patrol,-1),
			(party_set_slot,'p_town_4',slot_town_spawn_points,2500),
			(party_set_slot,'p_town_4',slot_party_type,spt_city),
			(party_set_slot,'p_town_4',slot_party_food,50000),
			(party_set_slot,'p_town_4',slot_party_icon,'icon_town'),
			(party_set_slot,'p_town_4',slot_party_icon_state,tis_normal),
			(party_set_slot,'p_town_4',slot_party_ai_state,null),
			(party_set_slot,'p_town_4',slot_party_ai_object,null),
			(party_set_slot,'p_town_4',slot_town_accumulated_rents,0),
			(party_set_slot,'p_town_4',slot_town_accumulated_tariffs,0),
			(party_set_slot,'p_town_4',slot_town_current_improvement,null),
			(party_set_slot,'p_town_4',slot_town_improvement_end_hour,null),
			(party_set_slot,'p_town_4',slot_town_housing_level,1),
			(party_set_slot,'p_town_4',slot_town_irrigation_level,1),
			(party_set_slot,'p_town_4',slot_town_mill_level,1),
			(party_set_slot,'p_town_4',slot_town_raided_by,null),
			(party_set_slot,'p_town_4',slot_town_state,sts_normal),
			(party_set_slot,'p_town_4',slot_town_raid_progress,null),
			(party_set_slot,'p_town_4',slot_town_recover_progress,null),
			(party_set_slot,'p_town_4',slot_town_production_bonus,1),
			(party_set_slot,'p_town_4',slot_town_siege_days,0),
			(party_set_slot,'p_town_4',slot_town_reserve_patrol,null),
			(party_set_slot,'p_town_4',slot_town_trade_good_productions_begin,null),
			(party_set_slot,'p_town_4',slot_town_trade_good_temp_productions_begin,null),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_town_4',slot_town_trade_good_price_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_town_4',slot_town_trade_good_abundance_array,'$return'),
			(party_set_slot,'p_town_4',slot_town_tax_rate,100),
			(party_set_slot,'p_town_4',slot_town_shoen,null),
			(party_set_slot,'p_town_4',slot_town_prefecture_array,null),
			(party_set_slot,'p_town_4',slot_town_reinforcements_a,'pt_town_reinforcements_a'),
			(party_set_slot,'p_town_4',slot_town_reinforcements_b,'pt_town_reinforcements_b'),
			(party_set_slot,'p_town_4',slot_town_reinforcements_c,'pt_town_reinforcements_c'),
			(party_set_slot,'p_town_4',slot_town_population,2500),
			(party_set_slot,'p_town_4',slot_town_population_max,10000),
			(party_set_slot,'p_town_4',slot_town_population_growth_factor,1),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_town_4',slot_town_demand_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_town_4',slot_town_storehouse_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_town_4',slot_town_facility_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_town_4',slot_town_surplus_array,'$return'),

			(party_set_slot,'p_town_5',slot_town_center,0),
			(party_set_slot,'p_town_5',slot_town_castle,0),
			(party_set_slot,'p_town_5',slot_town_inn,0),
			(party_set_slot,'p_town_5',slot_town_store,0),
			(party_set_slot,'p_town_5',slot_town_smithy,0),
			(party_set_slot,'p_town_5',slot_town_capital,himeji),
			(party_set_slot,'p_town_5',slot_town_dojo,0),
			(party_set_slot,'p_town_5',slot_town_sensei,-1),
			(party_set_slot,'p_town_5',slot_town_kokujin,'trp_town_5_kokujin'),
			(party_set_slot,'p_town_5',slot_town_shugo,-1),
			(party_set_slot,'p_town_5',slot_town_innkeeper,'trp_town_5_innkeeper'),
			(party_set_slot,'p_town_5',slot_town_weaponsmith,'trp_town_5_weaponsmith'),
			(party_set_slot,'p_town_5',slot_town_armorer,'trp_town_5_armorer'),
			(party_set_slot,'p_town_5',slot_town_merchant,'trp_town_5_merchant'),
			(party_set_slot,'p_town_5',slot_town_broker,null),
			(party_set_slot,'p_town_5',slot_town_moneychanger,null),
			(party_set_slot,'p_town_5',slot_town_fishmonger,'trp_town_5_fishmonger'),
			(party_set_slot,'p_town_5',slot_town_horse_trader,null),
			(party_set_slot,'p_town_5',slot_town_export_good,itm_kyoto_sake),
			(party_set_slot,'p_town_5',slot_town_export_rate,100),
			(party_set_slot,'p_town_5',slot_town_import_good,itm_salt),
			(party_set_slot,'p_town_5',slot_town_import_rate,100),
			(party_set_slot,'p_town_5',slot_town_terrain,ter_seaside),
			(party_set_slot,'p_town_5',slot_town_size,ct_large_town),
			(party_set_slot,'p_town_5',slot_town_mercs,'p_town_5_mercs'),
			(party_set_slot,'p_town_5',slot_town_trade_hub,0),
			(party_set_slot,'p_town_5',slot_town_trade_dest,himeji),
			(party_set_slot,'p_town_5',slot_town_trade_month,7),
			(party_set_slot,'p_town_5',slot_town_att_to_player,att_cautious),
			(party_set_slot,'p_town_5',slot_town_player_relation,0),
			(party_set_slot,'p_town_5',slot_town_import_demand,3),
			(party_set_slot,'p_town_5',slot_town_export_demand,3),
			(party_set_slot,'p_town_5',slot_town_demand,0),
			(call_script,'script_town_init_trade_dest','p_town_5',himeji,null,null,null,null,null),
			(party_set_slot,'p_town_5',slot_town_treasury,18000),
			(party_set_slot,'p_town_5',slot_town_garrison_source,'p_town_garrison_source'),
			(party_set_slot,'p_town_5',slot_town_siege_active,0),
			(party_set_slot,'p_town_5',slot_town_under_siege,false),
			(party_set_slot,'p_town_5',slot_town_is_besieged_by,null),
			(party_set_slot,'p_town_5',slot_town_initial_faction,0),
			(party_set_slot,'p_town_5',slot_town_scene_flags,0),
			(party_set_slot,'p_town_5',slot_town_reserve_patrol,-1),
			(party_set_slot,'p_town_5',slot_town_spawn_points,2500),
			(party_set_slot,'p_town_5',slot_party_type,spt_city),
			(party_set_slot,'p_town_5',slot_party_food,50000),
			(party_set_slot,'p_town_5',slot_party_icon,'icon_town'),
			(party_set_slot,'p_town_5',slot_party_icon_state,tis_normal),
			(party_set_slot,'p_town_5',slot_party_ai_state,null),
			(party_set_slot,'p_town_5',slot_party_ai_object,null),
			(party_set_slot,'p_town_5',slot_town_accumulated_rents,0),
			(party_set_slot,'p_town_5',slot_town_accumulated_tariffs,0),
			(party_set_slot,'p_town_5',slot_town_current_improvement,null),
			(party_set_slot,'p_town_5',slot_town_improvement_end_hour,null),
			(party_set_slot,'p_town_5',slot_town_housing_level,1),
			(party_set_slot,'p_town_5',slot_town_irrigation_level,1),
			(party_set_slot,'p_town_5',slot_town_mill_level,1),
			(party_set_slot,'p_town_5',slot_town_raided_by,null),
			(party_set_slot,'p_town_5',slot_town_state,sts_normal),
			(party_set_slot,'p_town_5',slot_town_raid_progress,null),
			(party_set_slot,'p_town_5',slot_town_recover_progress,null),
			(party_set_slot,'p_town_5',slot_town_production_bonus,1),
			(party_set_slot,'p_town_5',slot_town_siege_days,0),
			(party_set_slot,'p_town_5',slot_town_reserve_patrol,null),
			(party_set_slot,'p_town_5',slot_town_trade_good_productions_begin,null),
			(party_set_slot,'p_town_5',slot_town_trade_good_temp_productions_begin,null),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_town_5',slot_town_trade_good_price_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_town_5',slot_town_trade_good_abundance_array,'$return'),
			(party_set_slot,'p_town_5',slot_town_tax_rate,100),
			(party_set_slot,'p_town_5',slot_town_shoen,null),
			(party_set_slot,'p_town_5',slot_town_prefecture_array,null),
			(party_set_slot,'p_town_5',slot_town_reinforcements_a,'pt_town_reinforcements_a'),
			(party_set_slot,'p_town_5',slot_town_reinforcements_b,'pt_town_reinforcements_b'),
			(party_set_slot,'p_town_5',slot_town_reinforcements_c,'pt_town_reinforcements_c'),
			(party_set_slot,'p_town_5',slot_town_population,2500),
			(party_set_slot,'p_town_5',slot_town_population_max,10000),
			(party_set_slot,'p_town_5',slot_town_population_growth_factor,1),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_town_5',slot_town_demand_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_town_5',slot_town_storehouse_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_town_5',slot_town_facility_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_town_5',slot_town_surplus_array,'$return'),

			(party_set_slot,'p_town_6',slot_town_center,0),
			(party_set_slot,'p_town_6',slot_town_castle,0),
			(party_set_slot,'p_town_6',slot_town_inn,0),
			(party_set_slot,'p_town_6',slot_town_store,0),
			(party_set_slot,'p_town_6',slot_town_smithy,0),
			(party_set_slot,'p_town_6',slot_town_capital,obama),
			(party_set_slot,'p_town_6',slot_town_dojo,0),
			(party_set_slot,'p_town_6',slot_town_sensei,-1),
			(party_set_slot,'p_town_6',slot_town_kokujin,'trp_town_6_kokujin'),
			(party_set_slot,'p_town_6',slot_town_shugo,-1),
			(party_set_slot,'p_town_6',slot_town_innkeeper,'trp_town_6_innkeeper'),
			(party_set_slot,'p_town_6',slot_town_weaponsmith,'trp_town_6_weaponsmith'),
			(party_set_slot,'p_town_6',slot_town_armorer,'trp_town_6_armorer'),
			(party_set_slot,'p_town_6',slot_town_merchant,'trp_town_6_merchant'),
			(party_set_slot,'p_town_6',slot_town_broker,null),
			(party_set_slot,'p_town_6',slot_town_moneychanger,null),
			(party_set_slot,'p_town_6',slot_town_fishmonger,'trp_town_6_fishmonger'),
			(party_set_slot,'p_town_6',slot_town_horse_trader,null),
			(party_set_slot,'p_town_6',slot_town_export_good,itm_kyoto_sake),
			(party_set_slot,'p_town_6',slot_town_export_rate,100),
			(party_set_slot,'p_town_6',slot_town_import_good,itm_salt),
			(party_set_slot,'p_town_6',slot_town_import_rate,100),
			(party_set_slot,'p_town_6',slot_town_terrain,ter_lakeside),
			(party_set_slot,'p_town_6',slot_town_size,ct_town),
			(party_set_slot,'p_town_6',slot_town_mercs,'p_town_6_mercs'),
			(party_set_slot,'p_town_6',slot_town_trade_hub,0),
			(party_set_slot,'p_town_6',slot_town_trade_dest,otsu),
			(party_set_slot,'p_town_6',slot_town_trade_month,10),
			(party_set_slot,'p_town_6',slot_town_att_to_player,att_cautious),
			(party_set_slot,'p_town_6',slot_town_player_relation,0),
			(party_set_slot,'p_town_6',slot_town_import_demand,3),
			(party_set_slot,'p_town_6',slot_town_export_demand,3),
			(party_set_slot,'p_town_6',slot_town_demand,0),
			(call_script,'script_town_init_trade_dest','p_town_6',otsu,null,null,null,null,null),
			(party_set_slot,'p_town_6',slot_town_treasury,18000),
			(party_set_slot,'p_town_6',slot_town_garrison_source,'p_town_garrison_source'),
			(party_set_slot,'p_town_6',slot_town_siege_active,0),
			(party_set_slot,'p_town_6',slot_town_under_siege,false),
			(party_set_slot,'p_town_6',slot_town_is_besieged_by,null),
			(party_set_slot,'p_town_6',slot_town_initial_faction,0),
			(party_set_slot,'p_town_6',slot_town_scene_flags,0),
			(party_set_slot,'p_town_6',slot_town_reserve_patrol,-1),
			(party_set_slot,'p_town_6',slot_town_spawn_points,2500),
			(party_set_slot,'p_town_6',slot_party_type,spt_city),
			(party_set_slot,'p_town_6',slot_party_food,50000),
			(party_set_slot,'p_town_6',slot_party_icon,'icon_town'),
			(party_set_slot,'p_town_6',slot_party_icon_state,tis_normal),
			(party_set_slot,'p_town_6',slot_party_ai_state,null),
			(party_set_slot,'p_town_6',slot_party_ai_object,null),
			(party_set_slot,'p_town_6',slot_town_accumulated_rents,0),
			(party_set_slot,'p_town_6',slot_town_accumulated_tariffs,0),
			(party_set_slot,'p_town_6',slot_town_current_improvement,null),
			(party_set_slot,'p_town_6',slot_town_improvement_end_hour,null),
			(party_set_slot,'p_town_6',slot_town_housing_level,1),
			(party_set_slot,'p_town_6',slot_town_irrigation_level,1),
			(party_set_slot,'p_town_6',slot_town_mill_level,1),
			(party_set_slot,'p_town_6',slot_town_raided_by,null),
			(party_set_slot,'p_town_6',slot_town_state,sts_normal),
			(party_set_slot,'p_town_6',slot_town_raid_progress,null),
			(party_set_slot,'p_town_6',slot_town_recover_progress,null),
			(party_set_slot,'p_town_6',slot_town_production_bonus,1),
			(party_set_slot,'p_town_6',slot_town_siege_days,0),
			(party_set_slot,'p_town_6',slot_town_reserve_patrol,null),
			(party_set_slot,'p_town_6',slot_town_trade_good_productions_begin,null),
			(party_set_slot,'p_town_6',slot_town_trade_good_temp_productions_begin,null),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_town_6',slot_town_trade_good_price_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_town_6',slot_town_trade_good_abundance_array,'$return'),
			(party_set_slot,'p_town_6',slot_town_tax_rate,100),
			(party_set_slot,'p_town_6',slot_town_shoen,null),
			(party_set_slot,'p_town_6',slot_town_prefecture_array,null),
			(party_set_slot,'p_town_6',slot_town_reinforcements_a,'pt_town_reinforcements_a'),
			(party_set_slot,'p_town_6',slot_town_reinforcements_b,'pt_town_reinforcements_b'),
			(party_set_slot,'p_town_6',slot_town_reinforcements_c,'pt_town_reinforcements_c'),
			(party_set_slot,'p_town_6',slot_town_population,2500),
			(party_set_slot,'p_town_6',slot_town_population_max,10000),
			(party_set_slot,'p_town_6',slot_town_population_growth_factor,1),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_town_6',slot_town_demand_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_town_6',slot_town_storehouse_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_town_6',slot_town_facility_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_town_6',slot_town_surplus_array,'$return'),

			(party_set_slot,'p_town_7',slot_town_center,0),
			(party_set_slot,'p_town_7',slot_town_castle,0),
			(party_set_slot,'p_town_7',slot_town_inn,0),
			(party_set_slot,'p_town_7',slot_town_store,0),
			(party_set_slot,'p_town_7',slot_town_smithy,0),
			(party_set_slot,'p_town_7',slot_town_capital,hyogo),
			(party_set_slot,'p_town_7',slot_town_dojo,'scn_yodo_dojo'),
			(party_set_slot,'p_town_7',slot_town_sensei,'trp_tomomoto'),
			(party_set_slot,'p_town_7',slot_town_kokujin,'trp_town_7_kokujin'),
			(party_set_slot,'p_town_7',slot_town_shugo,-1),
			(party_set_slot,'p_town_7',slot_town_innkeeper,'trp_town_7_innkeeper'),
			(party_set_slot,'p_town_7',slot_town_weaponsmith,'trp_town_7_weaponsmith'),
			(party_set_slot,'p_town_7',slot_town_armorer,'trp_town_7_armorer'),
			(party_set_slot,'p_town_7',slot_town_merchant,'trp_town_7_merchant'),
			(party_set_slot,'p_town_7',slot_town_broker,null),
			(party_set_slot,'p_town_7',slot_town_moneychanger,null),
			(party_set_slot,'p_town_7',slot_town_fishmonger,'trp_town_7_fishmonger'),
			(party_set_slot,'p_town_7',slot_town_horse_trader,null),
			(party_set_slot,'p_town_7',slot_town_export_good,itm_kyoto_sake),
			(party_set_slot,'p_town_7',slot_town_export_rate,100),
			(party_set_slot,'p_town_7',slot_town_import_good,itm_salt),
			(party_set_slot,'p_town_7',slot_town_import_rate,100),
			(party_set_slot,'p_town_7',slot_town_terrain,ter_lowland),
			(party_set_slot,'p_town_7',slot_town_size,ct_town),
			(party_set_slot,'p_town_7',slot_town_mercs,'p_town_7_mercs'),
			(party_set_slot,'p_town_7',slot_town_trade_hub,0),
			(party_set_slot,'p_town_7',slot_town_trade_dest,hyogo),
			(party_set_slot,'p_town_7',slot_town_trade_month,4),
			(party_set_slot,'p_town_7',slot_town_att_to_player,att_cautious),
			(party_set_slot,'p_town_7',slot_town_player_relation,0),
			(party_set_slot,'p_town_7',slot_town_import_demand,3),
			(party_set_slot,'p_town_7',slot_town_export_demand,3),
			(party_set_slot,'p_town_7',slot_town_demand,0),
			(call_script,'script_town_init_trade_dest','p_town_7',hyogo,null,null,null,null,null),
			(party_set_slot,'p_town_7',slot_town_treasury,18000),
			(party_set_slot,'p_town_7',slot_town_garrison_source,'p_town_garrison_source'),
			(party_set_slot,'p_town_7',slot_town_siege_active,0),
			(party_set_slot,'p_town_7',slot_town_under_siege,false),
			(party_set_slot,'p_town_7',slot_town_is_besieged_by,null),
			(party_set_slot,'p_town_7',slot_town_initial_faction,0),
			(party_set_slot,'p_town_7',slot_town_scene_flags,0),
			(party_set_slot,'p_town_7',slot_town_reserve_patrol,-1),
			(party_set_slot,'p_town_7',slot_town_spawn_points,2500),
			(party_set_slot,'p_town_7',slot_party_type,spt_city),
			(party_set_slot,'p_town_7',slot_party_food,50000),
			(party_set_slot,'p_town_7',slot_party_icon,'icon_town'),
			(party_set_slot,'p_town_7',slot_party_icon_state,tis_normal),
			(party_set_slot,'p_town_7',slot_party_ai_state,null),
			(party_set_slot,'p_town_7',slot_party_ai_object,null),
			(party_set_slot,'p_town_7',slot_town_accumulated_rents,0),
			(party_set_slot,'p_town_7',slot_town_accumulated_tariffs,0),
			(party_set_slot,'p_town_7',slot_town_current_improvement,null),
			(party_set_slot,'p_town_7',slot_town_improvement_end_hour,null),
			(party_set_slot,'p_town_7',slot_town_housing_level,1),
			(party_set_slot,'p_town_7',slot_town_irrigation_level,1),
			(party_set_slot,'p_town_7',slot_town_mill_level,1),
			(party_set_slot,'p_town_7',slot_town_raided_by,null),
			(party_set_slot,'p_town_7',slot_town_state,sts_normal),
			(party_set_slot,'p_town_7',slot_town_raid_progress,null),
			(party_set_slot,'p_town_7',slot_town_recover_progress,null),
			(party_set_slot,'p_town_7',slot_town_production_bonus,1),
			(party_set_slot,'p_town_7',slot_town_siege_days,0),
			(party_set_slot,'p_town_7',slot_town_reserve_patrol,null),
			(party_set_slot,'p_town_7',slot_town_trade_good_productions_begin,null),
			(party_set_slot,'p_town_7',slot_town_trade_good_temp_productions_begin,null),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_town_7',slot_town_trade_good_price_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_town_7',slot_town_trade_good_abundance_array,'$return'),
			(party_set_slot,'p_town_7',slot_town_tax_rate,100),
			(party_set_slot,'p_town_7',slot_town_shoen,null),
			(party_set_slot,'p_town_7',slot_town_prefecture_array,null),
			(party_set_slot,'p_town_7',slot_town_reinforcements_a,'pt_town_reinforcements_a'),
			(party_set_slot,'p_town_7',slot_town_reinforcements_b,'pt_town_reinforcements_b'),
			(party_set_slot,'p_town_7',slot_town_reinforcements_c,'pt_town_reinforcements_c'),
			(party_set_slot,'p_town_7',slot_town_population,2500),
			(party_set_slot,'p_town_7',slot_town_population_max,10000),
			(party_set_slot,'p_town_7',slot_town_population_growth_factor,1),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_town_7',slot_town_demand_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_town_7',slot_town_storehouse_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_town_7',slot_town_facility_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_town_7',slot_town_surplus_array,'$return'),

			(party_set_slot,'p_town_8',slot_town_center,0),
			(party_set_slot,'p_town_8',slot_town_castle,0),
			(party_set_slot,'p_town_8',slot_town_inn,0),
			(party_set_slot,'p_town_8',slot_town_store,0),
			(party_set_slot,'p_town_8',slot_town_smithy,0),
			(party_set_slot,'p_town_8',slot_town_capital,kakogawa),
			(party_set_slot,'p_town_8',slot_town_dojo,0),
			(party_set_slot,'p_town_8',slot_town_sensei,-1),
			(party_set_slot,'p_town_8',slot_town_kokujin,'trp_town_8_kokujin'),
			(party_set_slot,'p_town_8',slot_town_shugo,-1),
			(party_set_slot,'p_town_8',slot_town_innkeeper,'trp_town_8_innkeeper'),
			(party_set_slot,'p_town_8',slot_town_weaponsmith,'trp_town_8_weaponsmith'),
			(party_set_slot,'p_town_8',slot_town_armorer,'trp_town_8_armorer'),
			(party_set_slot,'p_town_8',slot_town_merchant,'trp_town_8_merchant'),
			(party_set_slot,'p_town_8',slot_town_broker,null),
			(party_set_slot,'p_town_8',slot_town_moneychanger,null),
			(party_set_slot,'p_town_8',slot_town_fishmonger,'trp_town_8_fishmonger'),
			(party_set_slot,'p_town_8',slot_town_horse_trader,null),
			(party_set_slot,'p_town_8',slot_town_export_good,itm_kyoto_sake),
			(party_set_slot,'p_town_8',slot_town_export_rate,100),
			(party_set_slot,'p_town_8',slot_town_import_good,itm_salt),
			(party_set_slot,'p_town_8',slot_town_import_rate,100),
			(party_set_slot,'p_town_8',slot_town_terrain,ter_lowland),
			(party_set_slot,'p_town_8',slot_town_size,ct_town),
			(party_set_slot,'p_town_8',slot_town_mercs,'p_town_8_mercs'),
			(party_set_slot,'p_town_8',slot_town_trade_hub,0),
			(party_set_slot,'p_town_8',slot_town_trade_dest,kakogawa),
			(party_set_slot,'p_town_8',slot_town_trade_month,7),
			(party_set_slot,'p_town_8',slot_town_att_to_player,att_cautious),
			(party_set_slot,'p_town_8',slot_town_player_relation,0),
			(party_set_slot,'p_town_8',slot_town_import_demand,3),
			(party_set_slot,'p_town_8',slot_town_export_demand,3),
			(party_set_slot,'p_town_8',slot_town_demand,0),
			(call_script,'script_town_init_trade_dest','p_town_8',kakogawa,null,null,null,null,null),
			(party_set_slot,'p_town_8',slot_town_treasury,18000),
			(party_set_slot,'p_town_8',slot_town_garrison_source,'p_town_garrison_source'),
			(party_set_slot,'p_town_8',slot_town_siege_active,0),
			(party_set_slot,'p_town_8',slot_town_under_siege,false),
			(party_set_slot,'p_town_8',slot_town_is_besieged_by,null),
			(party_set_slot,'p_town_8',slot_town_initial_faction,0),
			(party_set_slot,'p_town_8',slot_town_scene_flags,0),
			(party_set_slot,'p_town_8',slot_town_reserve_patrol,-1),
			(party_set_slot,'p_town_8',slot_town_spawn_points,2500),
			(party_set_slot,'p_town_8',slot_party_type,spt_city),
			(party_set_slot,'p_town_8',slot_party_food,50000),
			(party_set_slot,'p_town_8',slot_party_icon,'icon_town'),
			(party_set_slot,'p_town_8',slot_party_icon_state,tis_normal),
			(party_set_slot,'p_town_8',slot_party_ai_state,null),
			(party_set_slot,'p_town_8',slot_party_ai_object,null),
			(party_set_slot,'p_town_8',slot_town_accumulated_rents,0),
			(party_set_slot,'p_town_8',slot_town_accumulated_tariffs,0),
			(party_set_slot,'p_town_8',slot_town_current_improvement,null),
			(party_set_slot,'p_town_8',slot_town_improvement_end_hour,null),
			(party_set_slot,'p_town_8',slot_town_housing_level,1),
			(party_set_slot,'p_town_8',slot_town_irrigation_level,1),
			(party_set_slot,'p_town_8',slot_town_mill_level,1),
			(party_set_slot,'p_town_8',slot_town_raided_by,null),
			(party_set_slot,'p_town_8',slot_town_state,sts_normal),
			(party_set_slot,'p_town_8',slot_town_raid_progress,null),
			(party_set_slot,'p_town_8',slot_town_recover_progress,null),
			(party_set_slot,'p_town_8',slot_town_production_bonus,1),
			(party_set_slot,'p_town_8',slot_town_siege_days,0),
			(party_set_slot,'p_town_8',slot_town_reserve_patrol,null),
			(party_set_slot,'p_town_8',slot_town_trade_good_productions_begin,null),
			(party_set_slot,'p_town_8',slot_town_trade_good_temp_productions_begin,null),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_town_8',slot_town_trade_good_price_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_town_8',slot_town_trade_good_abundance_array,'$return'),
			(party_set_slot,'p_town_8',slot_town_tax_rate,100),
			(party_set_slot,'p_town_8',slot_town_shoen,null),
			(party_set_slot,'p_town_8',slot_town_prefecture_array,null),
			(party_set_slot,'p_town_8',slot_town_reinforcements_a,'pt_town_reinforcements_a'),
			(party_set_slot,'p_town_8',slot_town_reinforcements_b,'pt_town_reinforcements_b'),
			(party_set_slot,'p_town_8',slot_town_reinforcements_c,'pt_town_reinforcements_c'),
			(party_set_slot,'p_town_8',slot_town_population,2500),
			(party_set_slot,'p_town_8',slot_town_population_max,10000),
			(party_set_slot,'p_town_8',slot_town_population_growth_factor,1),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_town_8',slot_town_demand_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_town_8',slot_town_storehouse_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_town_8',slot_town_facility_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_town_8',slot_town_surplus_array,'$return'),

			(party_set_slot,'p_town_9',slot_town_center,0),
			(party_set_slot,'p_town_9',slot_town_castle,0),
			(party_set_slot,'p_town_9',slot_town_inn,0),
			(party_set_slot,'p_town_9',slot_town_store,0),
			(party_set_slot,'p_town_9',slot_town_smithy,0),
			(party_set_slot,'p_town_9',slot_town_capital,sakai),
			(party_set_slot,'p_town_9',slot_town_dojo,0),
			(party_set_slot,'p_town_9',slot_town_sensei,-1),
			(party_set_slot,'p_town_9',slot_town_kokujin,'trp_town_9_kokujin'),
			(party_set_slot,'p_town_9',slot_town_shugo,-1),
			(party_set_slot,'p_town_9',slot_town_innkeeper,'trp_town_9_innkeeper'),
			(party_set_slot,'p_town_9',slot_town_weaponsmith,'trp_town_9_weaponsmith'),
			(party_set_slot,'p_town_9',slot_town_armorer,'trp_town_9_armorer'),
			(party_set_slot,'p_town_9',slot_town_merchant,'trp_town_9_merchant'),
			(party_set_slot,'p_town_9',slot_town_broker,null),
			(party_set_slot,'p_town_9',slot_town_moneychanger,null),
			(party_set_slot,'p_town_9',slot_town_fishmonger,'trp_town_9_fishmonger'),
			(party_set_slot,'p_town_9',slot_town_horse_trader,null),
			(party_set_slot,'p_town_9',slot_town_export_good,itm_kyoto_sake),
			(party_set_slot,'p_town_9',slot_town_export_rate,100),
			(party_set_slot,'p_town_9',slot_town_import_good,itm_salt),
			(party_set_slot,'p_town_9',slot_town_import_rate,100),
			(party_set_slot,'p_town_9',slot_town_terrain,ter_seaside),
			(party_set_slot,'p_town_9',slot_town_size,ct_town),
			(party_set_slot,'p_town_9',slot_town_mercs,'p_town_9_mercs'),
			(party_set_slot,'p_town_9',slot_town_trade_hub,0),
			(party_set_slot,'p_town_9',slot_town_trade_dest,misaki),
			(party_set_slot,'p_town_9',slot_town_trade_month,10),
			(party_set_slot,'p_town_9',slot_town_att_to_player,att_cautious),
			(party_set_slot,'p_town_9',slot_town_player_relation,0),
			(party_set_slot,'p_town_9',slot_town_import_demand,3),
			(party_set_slot,'p_town_9',slot_town_export_demand,3),
			(party_set_slot,'p_town_9',slot_town_demand,0),
			(call_script,'script_town_init_trade_dest','p_town_9',misaki,null,null,null,null,null),
			(party_set_slot,'p_town_9',slot_town_treasury,18000),
			(party_set_slot,'p_town_9',slot_town_garrison_source,'p_town_garrison_source'),
			(party_set_slot,'p_town_9',slot_town_siege_active,0),
			(party_set_slot,'p_town_9',slot_town_under_siege,false),
			(party_set_slot,'p_town_9',slot_town_is_besieged_by,null),
			(party_set_slot,'p_town_9',slot_town_initial_faction,0),
			(party_set_slot,'p_town_9',slot_town_scene_flags,0),
			(party_set_slot,'p_town_9',slot_town_reserve_patrol,-1),
			(party_set_slot,'p_town_9',slot_town_spawn_points,2500),
			(party_set_slot,'p_town_9',slot_party_type,spt_city),
			(party_set_slot,'p_town_9',slot_party_food,50000),
			(party_set_slot,'p_town_9',slot_party_icon,'icon_town'),
			(party_set_slot,'p_town_9',slot_party_icon_state,tis_normal),
			(party_set_slot,'p_town_9',slot_party_ai_state,null),
			(party_set_slot,'p_town_9',slot_party_ai_object,null),
			(party_set_slot,'p_town_9',slot_town_accumulated_rents,0),
			(party_set_slot,'p_town_9',slot_town_accumulated_tariffs,0),
			(party_set_slot,'p_town_9',slot_town_current_improvement,null),
			(party_set_slot,'p_town_9',slot_town_improvement_end_hour,null),
			(party_set_slot,'p_town_9',slot_town_housing_level,1),
			(party_set_slot,'p_town_9',slot_town_irrigation_level,1),
			(party_set_slot,'p_town_9',slot_town_mill_level,1),
			(party_set_slot,'p_town_9',slot_town_raided_by,null),
			(party_set_slot,'p_town_9',slot_town_state,sts_normal),
			(party_set_slot,'p_town_9',slot_town_raid_progress,null),
			(party_set_slot,'p_town_9',slot_town_recover_progress,null),
			(party_set_slot,'p_town_9',slot_town_production_bonus,1),
			(party_set_slot,'p_town_9',slot_town_siege_days,0),
			(party_set_slot,'p_town_9',slot_town_reserve_patrol,null),
			(party_set_slot,'p_town_9',slot_town_trade_good_productions_begin,null),
			(party_set_slot,'p_town_9',slot_town_trade_good_temp_productions_begin,null),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_town_9',slot_town_trade_good_price_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_town_9',slot_town_trade_good_abundance_array,'$return'),
			(party_set_slot,'p_town_9',slot_town_tax_rate,100),
			(party_set_slot,'p_town_9',slot_town_shoen,null),
			(party_set_slot,'p_town_9',slot_town_prefecture_array,null),
			(party_set_slot,'p_town_9',slot_town_reinforcements_a,'pt_town_reinforcements_a'),
			(party_set_slot,'p_town_9',slot_town_reinforcements_b,'pt_town_reinforcements_b'),
			(party_set_slot,'p_town_9',slot_town_reinforcements_c,'pt_town_reinforcements_c'),
			(party_set_slot,'p_town_9',slot_town_population,2500),
			(party_set_slot,'p_town_9',slot_town_population_max,10000),
			(party_set_slot,'p_town_9',slot_town_population_growth_factor,1),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_town_9',slot_town_demand_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_town_9',slot_town_storehouse_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_town_9',slot_town_facility_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_town_9',slot_town_surplus_array,'$return'),

			(party_set_slot,'p_town_10',slot_town_center,0),
			(party_set_slot,'p_town_10',slot_town_castle,0),
			(party_set_slot,'p_town_10',slot_town_inn,0),
			(party_set_slot,'p_town_10',slot_town_store,0),
			(party_set_slot,'p_town_10',slot_town_smithy,0),
			(party_set_slot,'p_town_10',slot_town_capital,kakogawa),
			(party_set_slot,'p_town_10',slot_town_dojo,0),
			(party_set_slot,'p_town_10',slot_town_sensei,-1),
			(party_set_slot,'p_town_10',slot_town_kokujin,'trp_town_10_kokujin'),
			(party_set_slot,'p_town_10',slot_town_shugo,-1),
			(party_set_slot,'p_town_10',slot_town_innkeeper,'trp_town_10_innkeeper'),
			(party_set_slot,'p_town_10',slot_town_weaponsmith,'trp_town_10_weaponsmith'),
			(party_set_slot,'p_town_10',slot_town_armorer,'trp_town_10_armorer'),
			(party_set_slot,'p_town_10',slot_town_merchant,'trp_town_10_merchant'),
			(party_set_slot,'p_town_10',slot_town_broker,null),
			(party_set_slot,'p_town_10',slot_town_moneychanger,null),
			(party_set_slot,'p_town_10',slot_town_fishmonger,'trp_town_10_fishmonger'),
			(party_set_slot,'p_town_10',slot_town_horse_trader,null),
			(party_set_slot,'p_town_10',slot_town_export_good,itm_kyoto_sake),
			(party_set_slot,'p_town_10',slot_town_export_rate,100),
			(party_set_slot,'p_town_10',slot_town_import_good,itm_salt),
			(party_set_slot,'p_town_10',slot_town_import_rate,100),
			(party_set_slot,'p_town_10',slot_town_terrain,ter_island),
			(party_set_slot,'p_town_10',slot_town_size,ct_town),
			(party_set_slot,'p_town_10',slot_town_mercs,'p_town_10_mercs'),
			(party_set_slot,'p_town_10',slot_town_trade_hub,0),
			(party_set_slot,'p_town_10',slot_town_trade_dest,iwaji),
			(party_set_slot,'p_town_10',slot_town_trade_month,4),
			(party_set_slot,'p_town_10',slot_town_att_to_player,att_cautious),
			(party_set_slot,'p_town_10',slot_town_player_relation,0),
			(party_set_slot,'p_town_10',slot_town_import_demand,3),
			(party_set_slot,'p_town_10',slot_town_export_demand,3),
			(party_set_slot,'p_town_10',slot_town_demand,0),
			(call_script,'script_town_init_trade_dest','p_town_10',iwaji,null,null,null,null,null),
			(party_set_slot,'p_town_10',slot_town_treasury,18000),
			(party_set_slot,'p_town_10',slot_town_garrison_source,'p_town_garrison_source'),
			(party_set_slot,'p_town_10',slot_town_siege_active,0),
			(party_set_slot,'p_town_10',slot_town_under_siege,false),
			(party_set_slot,'p_town_10',slot_town_is_besieged_by,null),
			(party_set_slot,'p_town_10',slot_town_initial_faction,0),
			(party_set_slot,'p_town_10',slot_town_scene_flags,0),
			(party_set_slot,'p_town_10',slot_town_reserve_patrol,-1),
			(party_set_slot,'p_town_10',slot_town_spawn_points,2500),
			(party_set_slot,'p_town_10',slot_party_type,spt_city),
			(party_set_slot,'p_town_10',slot_party_food,50000),
			(party_set_slot,'p_town_10',slot_party_icon,'icon_town'),
			(party_set_slot,'p_town_10',slot_party_icon_state,tis_normal),
			(party_set_slot,'p_town_10',slot_party_ai_state,null),
			(party_set_slot,'p_town_10',slot_party_ai_object,null),
			(party_set_slot,'p_town_10',slot_town_accumulated_rents,0),
			(party_set_slot,'p_town_10',slot_town_accumulated_tariffs,0),
			(party_set_slot,'p_town_10',slot_town_current_improvement,null),
			(party_set_slot,'p_town_10',slot_town_improvement_end_hour,null),
			(party_set_slot,'p_town_10',slot_town_housing_level,1),
			(party_set_slot,'p_town_10',slot_town_irrigation_level,1),
			(party_set_slot,'p_town_10',slot_town_mill_level,1),
			(party_set_slot,'p_town_10',slot_town_raided_by,null),
			(party_set_slot,'p_town_10',slot_town_state,sts_normal),
			(party_set_slot,'p_town_10',slot_town_raid_progress,null),
			(party_set_slot,'p_town_10',slot_town_recover_progress,null),
			(party_set_slot,'p_town_10',slot_town_production_bonus,1),
			(party_set_slot,'p_town_10',slot_town_siege_days,0),
			(party_set_slot,'p_town_10',slot_town_reserve_patrol,null),
			(party_set_slot,'p_town_10',slot_town_trade_good_productions_begin,null),
			(party_set_slot,'p_town_10',slot_town_trade_good_temp_productions_begin,null),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_town_10',slot_town_trade_good_price_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_town_10',slot_town_trade_good_abundance_array,'$return'),
			(party_set_slot,'p_town_10',slot_town_tax_rate,100),
			(party_set_slot,'p_town_10',slot_town_shoen,null),
			(party_set_slot,'p_town_10',slot_town_prefecture_array,null),
			(party_set_slot,'p_town_10',slot_town_reinforcements_a,'pt_town_reinforcements_a'),
			(party_set_slot,'p_town_10',slot_town_reinforcements_b,'pt_town_reinforcements_b'),
			(party_set_slot,'p_town_10',slot_town_reinforcements_c,'pt_town_reinforcements_c'),
			(party_set_slot,'p_town_10',slot_town_population,2500),
			(party_set_slot,'p_town_10',slot_town_population_max,10000),
			(party_set_slot,'p_town_10',slot_town_population_growth_factor,1),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_town_10',slot_town_demand_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_town_10',slot_town_storehouse_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_town_10',slot_town_facility_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_town_10',slot_town_surplus_array,'$return'),

			(party_set_slot,'p_town_11',slot_town_center,0),
			(party_set_slot,'p_town_11',slot_town_castle,0),
			(party_set_slot,'p_town_11',slot_town_inn,0),
			(party_set_slot,'p_town_11',slot_town_store,0),
			(party_set_slot,'p_town_11',slot_town_smithy,0),
			(party_set_slot,'p_town_11',slot_town_capital,kameyama),
			(party_set_slot,'p_town_11',slot_town_dojo,0),
			(party_set_slot,'p_town_11',slot_town_sensei,-1),
			(party_set_slot,'p_town_11',slot_town_kokujin,'trp_town_11_kokujin'),
			(party_set_slot,'p_town_11',slot_town_shugo,-1),
			(party_set_slot,'p_town_11',slot_town_innkeeper,'trp_town_11_innkeeper'),
			(party_set_slot,'p_town_11',slot_town_weaponsmith,'trp_town_11_weaponsmith'),
			(party_set_slot,'p_town_11',slot_town_armorer,'trp_town_11_armorer'),
			(party_set_slot,'p_town_11',slot_town_merchant,'trp_town_11_merchant'),
			(party_set_slot,'p_town_11',slot_town_broker,null),
			(party_set_slot,'p_town_11',slot_town_moneychanger,null),
			(party_set_slot,'p_town_11',slot_town_fishmonger,'trp_town_11_fishmonger'),
			(party_set_slot,'p_town_11',slot_town_horse_trader,null),
			(party_set_slot,'p_town_11',slot_town_export_good,itm_kyoto_sake),
			(party_set_slot,'p_town_11',slot_town_export_rate,100),
			(party_set_slot,'p_town_11',slot_town_import_good,itm_salt),
			(party_set_slot,'p_town_11',slot_town_import_rate,100),
			(party_set_slot,'p_town_11',slot_town_terrain,ter_highland),
			(party_set_slot,'p_town_11',slot_town_size,ct_town),
			(party_set_slot,'p_town_11',slot_town_mercs,'p_town_11_mercs'),
			(party_set_slot,'p_town_11',slot_town_trade_hub,0),
			(party_set_slot,'p_town_11',slot_town_trade_dest,kameyama),
			(party_set_slot,'p_town_11',slot_town_trade_month,7),
			(party_set_slot,'p_town_11',slot_town_att_to_player,att_cautious),
			(party_set_slot,'p_town_11',slot_town_player_relation,0),
			(party_set_slot,'p_town_11',slot_town_import_demand,3),
			(party_set_slot,'p_town_11',slot_town_export_demand,3),
			(party_set_slot,'p_town_11',slot_town_demand,0),
			(call_script,'script_town_init_trade_dest','p_town_11',kameyama,null,null,null,null,null),
			(party_set_slot,'p_town_11',slot_town_treasury,18000),
			(party_set_slot,'p_town_11',slot_town_garrison_source,'p_town_garrison_source'),
			(party_set_slot,'p_town_11',slot_town_siege_active,0),
			(party_set_slot,'p_town_11',slot_town_under_siege,false),
			(party_set_slot,'p_town_11',slot_town_is_besieged_by,null),
			(party_set_slot,'p_town_11',slot_town_initial_faction,0),
			(party_set_slot,'p_town_11',slot_town_scene_flags,0),
			(party_set_slot,'p_town_11',slot_town_reserve_patrol,-1),
			(party_set_slot,'p_town_11',slot_town_spawn_points,2500),
			(party_set_slot,'p_town_11',slot_party_type,spt_city),
			(party_set_slot,'p_town_11',slot_party_food,50000),
			(party_set_slot,'p_town_11',slot_party_icon,'icon_town'),
			(party_set_slot,'p_town_11',slot_party_icon_state,tis_normal),
			(party_set_slot,'p_town_11',slot_party_ai_state,null),
			(party_set_slot,'p_town_11',slot_party_ai_object,null),
			(party_set_slot,'p_town_11',slot_town_accumulated_rents,0),
			(party_set_slot,'p_town_11',slot_town_accumulated_tariffs,0),
			(party_set_slot,'p_town_11',slot_town_current_improvement,null),
			(party_set_slot,'p_town_11',slot_town_improvement_end_hour,null),
			(party_set_slot,'p_town_11',slot_town_housing_level,1),
			(party_set_slot,'p_town_11',slot_town_irrigation_level,1),
			(party_set_slot,'p_town_11',slot_town_mill_level,1),
			(party_set_slot,'p_town_11',slot_town_raided_by,null),
			(party_set_slot,'p_town_11',slot_town_state,sts_normal),
			(party_set_slot,'p_town_11',slot_town_raid_progress,null),
			(party_set_slot,'p_town_11',slot_town_recover_progress,null),
			(party_set_slot,'p_town_11',slot_town_production_bonus,1),
			(party_set_slot,'p_town_11',slot_town_siege_days,0),
			(party_set_slot,'p_town_11',slot_town_reserve_patrol,null),
			(party_set_slot,'p_town_11',slot_town_trade_good_productions_begin,null),
			(party_set_slot,'p_town_11',slot_town_trade_good_temp_productions_begin,null),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_town_11',slot_town_trade_good_price_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_town_11',slot_town_trade_good_abundance_array,'$return'),
			(party_set_slot,'p_town_11',slot_town_tax_rate,100),
			(party_set_slot,'p_town_11',slot_town_shoen,null),
			(party_set_slot,'p_town_11',slot_town_prefecture_array,null),
			(party_set_slot,'p_town_11',slot_town_reinforcements_a,'pt_town_reinforcements_a'),
			(party_set_slot,'p_town_11',slot_town_reinforcements_b,'pt_town_reinforcements_b'),
			(party_set_slot,'p_town_11',slot_town_reinforcements_c,'pt_town_reinforcements_c'),
			(party_set_slot,'p_town_11',slot_town_population,2500),
			(party_set_slot,'p_town_11',slot_town_population_max,10000),
			(party_set_slot,'p_town_11',slot_town_population_growth_factor,1),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_town_11',slot_town_demand_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_town_11',slot_town_storehouse_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_town_11',slot_town_facility_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_town_11',slot_town_surplus_array,'$return'),

			(party_set_slot,'p_town_12',slot_town_center,0),
			(party_set_slot,'p_town_12',slot_town_castle,0),
			(party_set_slot,'p_town_12',slot_town_inn,0),
			(party_set_slot,'p_town_12',slot_town_store,0),
			(party_set_slot,'p_town_12',slot_town_smithy,0),
			(party_set_slot,'p_town_12',slot_town_capital,wakayama),
			(party_set_slot,'p_town_12',slot_town_dojo,0),
			(party_set_slot,'p_town_12',slot_town_sensei,-1),
			(party_set_slot,'p_town_12',slot_town_kokujin,'trp_town_12_kokujin'),
			(party_set_slot,'p_town_12',slot_town_shugo,-1),
			(party_set_slot,'p_town_12',slot_town_innkeeper,'trp_town_12_innkeeper'),
			(party_set_slot,'p_town_12',slot_town_weaponsmith,'trp_town_12_weaponsmith'),
			(party_set_slot,'p_town_12',slot_town_armorer,'trp_town_12_armorer'),
			(party_set_slot,'p_town_12',slot_town_merchant,'trp_town_12_merchant'),
			(party_set_slot,'p_town_12',slot_town_broker,null),
			(party_set_slot,'p_town_12',slot_town_moneychanger,null),
			(party_set_slot,'p_town_12',slot_town_fishmonger,'trp_town_12_fishmonger'),
			(party_set_slot,'p_town_12',slot_town_horse_trader,null),
			(party_set_slot,'p_town_12',slot_town_export_good,itm_kyoto_sake),
			(party_set_slot,'p_town_12',slot_town_export_rate,100),
			(party_set_slot,'p_town_12',slot_town_import_good,itm_salt),
			(party_set_slot,'p_town_12',slot_town_import_rate,100),
			(party_set_slot,'p_town_12',slot_town_terrain,ter_high_valley),
			(party_set_slot,'p_town_12',slot_town_size,ct_town),
			(party_set_slot,'p_town_12',slot_town_mercs,'p_town_12_mercs'),
			(party_set_slot,'p_town_12',slot_town_trade_hub,0),
			(party_set_slot,'p_town_12',slot_town_trade_dest,naga),
			(party_set_slot,'p_town_12',slot_town_trade_month,10),
			(party_set_slot,'p_town_12',slot_town_att_to_player,att_cautious),
			(party_set_slot,'p_town_12',slot_town_player_relation,0),
			(party_set_slot,'p_town_12',slot_town_import_demand,3),
			(party_set_slot,'p_town_12',slot_town_export_demand,3),
			(party_set_slot,'p_town_12',slot_town_demand,0),
			(call_script,'script_town_init_trade_dest','p_town_12',naga,null,null,null,null,null),
			(party_set_slot,'p_town_12',slot_town_treasury,18000),
			(party_set_slot,'p_town_12',slot_town_garrison_source,'p_town_garrison_source'),
			(party_set_slot,'p_town_12',slot_town_siege_active,0),
			(party_set_slot,'p_town_12',slot_town_under_siege,false),
			(party_set_slot,'p_town_12',slot_town_is_besieged_by,null),
			(party_set_slot,'p_town_12',slot_town_initial_faction,0),
			(party_set_slot,'p_town_12',slot_town_scene_flags,0),
			(party_set_slot,'p_town_12',slot_town_reserve_patrol,-1),
			(party_set_slot,'p_town_12',slot_town_spawn_points,2500),
			(party_set_slot,'p_town_12',slot_party_type,spt_city),
			(party_set_slot,'p_town_12',slot_party_food,50000),
			(party_set_slot,'p_town_12',slot_party_icon,'icon_town'),
			(party_set_slot,'p_town_12',slot_party_icon_state,tis_normal),
			(party_set_slot,'p_town_12',slot_party_ai_state,null),
			(party_set_slot,'p_town_12',slot_party_ai_object,null),
			(party_set_slot,'p_town_12',slot_town_accumulated_rents,0),
			(party_set_slot,'p_town_12',slot_town_accumulated_tariffs,0),
			(party_set_slot,'p_town_12',slot_town_current_improvement,null),
			(party_set_slot,'p_town_12',slot_town_improvement_end_hour,null),
			(party_set_slot,'p_town_12',slot_town_housing_level,1),
			(party_set_slot,'p_town_12',slot_town_irrigation_level,1),
			(party_set_slot,'p_town_12',slot_town_mill_level,1),
			(party_set_slot,'p_town_12',slot_town_raided_by,null),
			(party_set_slot,'p_town_12',slot_town_state,sts_normal),
			(party_set_slot,'p_town_12',slot_town_raid_progress,null),
			(party_set_slot,'p_town_12',slot_town_recover_progress,null),
			(party_set_slot,'p_town_12',slot_town_production_bonus,1),
			(party_set_slot,'p_town_12',slot_town_siege_days,0),
			(party_set_slot,'p_town_12',slot_town_reserve_patrol,null),
			(party_set_slot,'p_town_12',slot_town_trade_good_productions_begin,null),
			(party_set_slot,'p_town_12',slot_town_trade_good_temp_productions_begin,null),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_town_12',slot_town_trade_good_price_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_town_12',slot_town_trade_good_abundance_array,'$return'),
			(party_set_slot,'p_town_12',slot_town_tax_rate,100),
			(party_set_slot,'p_town_12',slot_town_shoen,null),
			(party_set_slot,'p_town_12',slot_town_prefecture_array,null),
			(party_set_slot,'p_town_12',slot_town_reinforcements_a,'pt_town_reinforcements_a'),
			(party_set_slot,'p_town_12',slot_town_reinforcements_b,'pt_town_reinforcements_b'),
			(party_set_slot,'p_town_12',slot_town_reinforcements_c,'pt_town_reinforcements_c'),
			(party_set_slot,'p_town_12',slot_town_population,2500),
			(party_set_slot,'p_town_12',slot_town_population_max,10000),
			(party_set_slot,'p_town_12',slot_town_population_growth_factor,1),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_town_12',slot_town_demand_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_town_12',slot_town_storehouse_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_town_12',slot_town_facility_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_town_12',slot_town_surplus_array,'$return'),

			(party_set_slot,'p_town_13',slot_town_center,0),
			(party_set_slot,'p_town_13',slot_town_castle,0),
			(party_set_slot,'p_town_13',slot_town_inn,0),
			(party_set_slot,'p_town_13',slot_town_store,0),
			(party_set_slot,'p_town_13',slot_town_smithy,0),
			(party_set_slot,'p_town_13',slot_town_capital,fukuchiyama),
			(party_set_slot,'p_town_13',slot_town_dojo,0),
			(party_set_slot,'p_town_13',slot_town_sensei,-1),
			(party_set_slot,'p_town_13',slot_town_kokujin,'trp_town_13_kokujin'),
			(party_set_slot,'p_town_13',slot_town_shugo,-1),
			(party_set_slot,'p_town_13',slot_town_innkeeper,'trp_town_13_innkeeper'),
			(party_set_slot,'p_town_13',slot_town_weaponsmith,'trp_town_13_weaponsmith'),
			(party_set_slot,'p_town_13',slot_town_armorer,'trp_town_13_armorer'),
			(party_set_slot,'p_town_13',slot_town_merchant,'trp_town_13_merchant'),
			(party_set_slot,'p_town_13',slot_town_broker,'trp_broker_13'),
			(party_set_slot,'p_town_13',slot_town_moneychanger,null),
			(party_set_slot,'p_town_13',slot_town_fishmonger,'trp_town_13_fishmonger'),
			(party_set_slot,'p_town_13',slot_town_horse_trader,null),
			(party_set_slot,'p_town_13',slot_town_export_good,itm_kyoto_sake),
			(party_set_slot,'p_town_13',slot_town_export_rate,100),
			(party_set_slot,'p_town_13',slot_town_import_good,itm_salt),
			(party_set_slot,'p_town_13',slot_town_import_rate,100),
			(party_set_slot,'p_town_13',slot_town_terrain,ter_highland),
			(party_set_slot,'p_town_13',slot_town_size,ct_town),
			(party_set_slot,'p_town_13',slot_town_mercs,'p_town_13_mercs'),
			(party_set_slot,'p_town_13',slot_town_trade_hub,0),
			(party_set_slot,'p_town_13',slot_town_trade_dest,kameyama),
			(party_set_slot,'p_town_13',slot_town_trade_month,4),
			(party_set_slot,'p_town_13',slot_town_att_to_player,att_cautious),
			(party_set_slot,'p_town_13',slot_town_player_relation,0),
			(party_set_slot,'p_town_13',slot_town_import_demand,3),
			(party_set_slot,'p_town_13',slot_town_export_demand,3),
			(party_set_slot,'p_town_13',slot_town_demand,0),
			(call_script,'script_town_init_trade_dest','p_town_13',kameyama,null,null,null,null,null),
			(party_set_slot,'p_town_13',slot_town_treasury,18000),
			(party_set_slot,'p_town_13',slot_town_garrison_source,'p_town_garrison_source'),
			(party_set_slot,'p_town_13',slot_town_siege_active,0),
			(party_set_slot,'p_town_13',slot_town_under_siege,false),
			(party_set_slot,'p_town_13',slot_town_is_besieged_by,null),
			(party_set_slot,'p_town_13',slot_town_initial_faction,0),
			(party_set_slot,'p_town_13',slot_town_scene_flags,0),
			(party_set_slot,'p_town_13',slot_town_reserve_patrol,-1),
			(party_set_slot,'p_town_13',slot_town_spawn_points,2500),
			(party_set_slot,'p_town_13',slot_party_type,spt_city),
			(party_set_slot,'p_town_13',slot_party_food,50000),
			(party_set_slot,'p_town_13',slot_party_icon,'icon_town'),
			(party_set_slot,'p_town_13',slot_party_icon_state,tis_normal),
			(party_set_slot,'p_town_13',slot_party_ai_state,null),
			(party_set_slot,'p_town_13',slot_party_ai_object,null),
			(party_set_slot,'p_town_13',slot_town_accumulated_rents,0),
			(party_set_slot,'p_town_13',slot_town_accumulated_tariffs,0),
			(party_set_slot,'p_town_13',slot_town_current_improvement,null),
			(party_set_slot,'p_town_13',slot_town_improvement_end_hour,null),
			(party_set_slot,'p_town_13',slot_town_housing_level,1),
			(party_set_slot,'p_town_13',slot_town_irrigation_level,1),
			(party_set_slot,'p_town_13',slot_town_mill_level,1),
			(party_set_slot,'p_town_13',slot_town_raided_by,null),
			(party_set_slot,'p_town_13',slot_town_state,sts_normal),
			(party_set_slot,'p_town_13',slot_town_raid_progress,null),
			(party_set_slot,'p_town_13',slot_town_recover_progress,null),
			(party_set_slot,'p_town_13',slot_town_production_bonus,1),
			(party_set_slot,'p_town_13',slot_town_siege_days,0),
			(party_set_slot,'p_town_13',slot_town_reserve_patrol,null),
			(party_set_slot,'p_town_13',slot_town_trade_good_productions_begin,null),
			(party_set_slot,'p_town_13',slot_town_trade_good_temp_productions_begin,null),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_town_13',slot_town_trade_good_price_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_town_13',slot_town_trade_good_abundance_array,'$return'),
			(party_set_slot,'p_town_13',slot_town_tax_rate,100),
			(party_set_slot,'p_town_13',slot_town_shoen,null),
			(party_set_slot,'p_town_13',slot_town_prefecture_array,null),
			(party_set_slot,'p_town_13',slot_town_reinforcements_a,'pt_town_reinforcements_a'),
			(party_set_slot,'p_town_13',slot_town_reinforcements_b,'pt_town_reinforcements_b'),
			(party_set_slot,'p_town_13',slot_town_reinforcements_c,'pt_town_reinforcements_c'),
			(party_set_slot,'p_town_13',slot_town_population,2500),
			(party_set_slot,'p_town_13',slot_town_population_max,10000),
			(party_set_slot,'p_town_13',slot_town_population_growth_factor,1),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_town_13',slot_town_demand_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_town_13',slot_town_storehouse_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_town_13',slot_town_facility_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_town_13',slot_town_surplus_array,'$return'),

			(party_set_slot,'p_town_14',slot_town_center,0),
			(party_set_slot,'p_town_14',slot_town_castle,0),
			(party_set_slot,'p_town_14',slot_town_inn,0),
			(party_set_slot,'p_town_14',slot_town_store,0),
			(party_set_slot,'p_town_14',slot_town_smithy,0),
			(party_set_slot,'p_town_14',slot_town_capital,nara),
			(party_set_slot,'p_town_14',slot_town_dojo,0),
			(party_set_slot,'p_town_14',slot_town_sensei,-1),
			(party_set_slot,'p_town_14',slot_town_kokujin,'trp_town_14_kokujin'),
			(party_set_slot,'p_town_14',slot_town_shugo,'trp_ueno_shugo'),
			(party_set_slot,'p_town_14',slot_town_innkeeper,'trp_town_14_innkeeper'),
			(party_set_slot,'p_town_14',slot_town_weaponsmith,'trp_town_14_weaponsmith'),
			(party_set_slot,'p_town_14',slot_town_armorer,'trp_town_14_armorer'),
			(party_set_slot,'p_town_14',slot_town_merchant,'trp_town_14_merchant'),
			(party_set_slot,'p_town_14',slot_town_broker,null),
			(party_set_slot,'p_town_14',slot_town_moneychanger,null),
			(party_set_slot,'p_town_14',slot_town_fishmonger,'trp_town_14_fishmonger'),
			(party_set_slot,'p_town_14',slot_town_horse_trader,null),
			(party_set_slot,'p_town_14',slot_town_export_good,itm_kyoto_sake),
			(party_set_slot,'p_town_14',slot_town_export_rate,100),
			(party_set_slot,'p_town_14',slot_town_import_good,itm_salt),
			(party_set_slot,'p_town_14',slot_town_import_rate,100),
			(party_set_slot,'p_town_14',slot_town_terrain,ter_highland),
			(party_set_slot,'p_town_14',slot_town_size,ct_town),
			(party_set_slot,'p_town_14',slot_town_mercs,'p_town_14_mercs'),
			(party_set_slot,'p_town_14',slot_town_trade_hub,1),
			(party_set_slot,'p_town_14',slot_town_trade_dest,-1),
			(party_set_slot,'p_town_14',slot_town_trade_month,7),
			(party_set_slot,'p_town_14',slot_town_att_to_player,att_cautious),
			(party_set_slot,'p_town_14',slot_town_player_relation,0),
			(party_set_slot,'p_town_14',slot_town_import_demand,3),
			(party_set_slot,'p_town_14',slot_town_export_demand,3),
			(party_set_slot,'p_town_14',slot_town_demand,0),
			(call_script,'script_town_init_trade_dest','p_town_14',wakayama,fujidera,null,null,null,null),
			(party_set_slot,'p_town_14',slot_town_treasury,18000),
			(party_set_slot,'p_town_14',slot_town_garrison_source,'p_town_garrison_source'),
			(party_set_slot,'p_town_14',slot_town_siege_active,0),
			(party_set_slot,'p_town_14',slot_town_under_siege,false),
			(party_set_slot,'p_town_14',slot_town_is_besieged_by,null),
			(party_set_slot,'p_town_14',slot_town_initial_faction,0),
			(party_set_slot,'p_town_14',slot_town_scene_flags,0),
			(party_set_slot,'p_town_14',slot_town_reserve_patrol,-1),
			(party_set_slot,'p_town_14',slot_town_spawn_points,2500),
			(party_set_slot,'p_town_14',slot_party_type,spt_city),
			(party_set_slot,'p_town_14',slot_party_food,50000),
			(party_set_slot,'p_town_14',slot_party_icon,'icon_town'),
			(party_set_slot,'p_town_14',slot_party_icon_state,tis_normal),
			(party_set_slot,'p_town_14',slot_party_ai_state,null),
			(party_set_slot,'p_town_14',slot_party_ai_object,null),
			(party_set_slot,'p_town_14',slot_town_accumulated_rents,0),
			(party_set_slot,'p_town_14',slot_town_accumulated_tariffs,0),
			(party_set_slot,'p_town_14',slot_town_current_improvement,null),
			(party_set_slot,'p_town_14',slot_town_improvement_end_hour,null),
			(party_set_slot,'p_town_14',slot_town_housing_level,1),
			(party_set_slot,'p_town_14',slot_town_irrigation_level,1),
			(party_set_slot,'p_town_14',slot_town_mill_level,1),
			(party_set_slot,'p_town_14',slot_town_raided_by,null),
			(party_set_slot,'p_town_14',slot_town_state,sts_normal),
			(party_set_slot,'p_town_14',slot_town_raid_progress,null),
			(party_set_slot,'p_town_14',slot_town_recover_progress,null),
			(party_set_slot,'p_town_14',slot_town_production_bonus,1),
			(party_set_slot,'p_town_14',slot_town_siege_days,0),
			(party_set_slot,'p_town_14',slot_town_reserve_patrol,null),
			(party_set_slot,'p_town_14',slot_town_trade_good_productions_begin,null),
			(party_set_slot,'p_town_14',slot_town_trade_good_temp_productions_begin,null),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_town_14',slot_town_trade_good_price_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_town_14',slot_town_trade_good_abundance_array,'$return'),
			(party_set_slot,'p_town_14',slot_town_tax_rate,100),
			(party_set_slot,'p_town_14',slot_town_shoen,null),
			(party_set_slot,'p_town_14',slot_town_prefecture_array,null),
			(party_set_slot,'p_town_14',slot_town_reinforcements_a,'pt_town_reinforcements_a'),
			(party_set_slot,'p_town_14',slot_town_reinforcements_b,'pt_town_reinforcements_b'),
			(party_set_slot,'p_town_14',slot_town_reinforcements_c,'pt_town_reinforcements_c'),
			(party_set_slot,'p_town_14',slot_town_population,2500),
			(party_set_slot,'p_town_14',slot_town_population_max,10000),
			(party_set_slot,'p_town_14',slot_town_population_growth_factor,1),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_town_14',slot_town_demand_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_town_14',slot_town_storehouse_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_town_14',slot_town_facility_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_town_14',slot_town_surplus_array,'$return'),

			(party_set_slot,'p_town_15',slot_town_center,0),
			(party_set_slot,'p_town_15',slot_town_castle,0),
			(party_set_slot,'p_town_15',slot_town_inn,0),
			(party_set_slot,'p_town_15',slot_town_store,0),
			(party_set_slot,'p_town_15',slot_town_smithy,0),
			(party_set_slot,'p_town_15',slot_town_capital,nara),
			(party_set_slot,'p_town_15',slot_town_dojo,0),
			(party_set_slot,'p_town_15',slot_town_sensei,-1),
			(party_set_slot,'p_town_15',slot_town_kokujin,'trp_town_15_kokujin'),
			(party_set_slot,'p_town_15',slot_town_shugo,-1),
			(party_set_slot,'p_town_15',slot_town_innkeeper,'trp_town_15_innkeeper'),
			(party_set_slot,'p_town_15',slot_town_weaponsmith,'trp_town_15_weaponsmith'),
			(party_set_slot,'p_town_15',slot_town_armorer,'trp_town_15_armorer'),
			(party_set_slot,'p_town_15',slot_town_merchant,'trp_town_15_merchant'),
			(party_set_slot,'p_town_15',slot_town_broker,null),
			(party_set_slot,'p_town_15',slot_town_moneychanger,null),
			(party_set_slot,'p_town_15',slot_town_fishmonger,'trp_town_15_fishmonger'),
			(party_set_slot,'p_town_15',slot_town_horse_trader,null),
			(party_set_slot,'p_town_15',slot_town_export_good,itm_kyoto_sake),
			(party_set_slot,'p_town_15',slot_town_export_rate,100),
			(party_set_slot,'p_town_15',slot_town_import_good,itm_salt),
			(party_set_slot,'p_town_15',slot_town_import_rate,100),
			(party_set_slot,'p_town_15',slot_town_terrain,ter_highland),
			(party_set_slot,'p_town_15',slot_town_size,ct_town),
			(party_set_slot,'p_town_15',slot_town_mercs,'p_town_15_mercs'),
			(party_set_slot,'p_town_15',slot_town_trade_hub,0),
			(party_set_slot,'p_town_15',slot_town_trade_dest,nara),
			(party_set_slot,'p_town_15',slot_town_trade_month,10),
			(party_set_slot,'p_town_15',slot_town_att_to_player,att_cautious),
			(party_set_slot,'p_town_15',slot_town_player_relation,0),
			(party_set_slot,'p_town_15',slot_town_import_demand,3),
			(party_set_slot,'p_town_15',slot_town_export_demand,3),
			(party_set_slot,'p_town_15',slot_town_demand,0),
			(call_script,'script_town_init_trade_dest','p_town_15',nara,null,null,null,null,null),
			(party_set_slot,'p_town_15',slot_town_treasury,18000),
			(party_set_slot,'p_town_15',slot_town_garrison_source,'p_town_garrison_source'),
			(party_set_slot,'p_town_15',slot_town_siege_active,0),
			(party_set_slot,'p_town_15',slot_town_under_siege,false),
			(party_set_slot,'p_town_15',slot_town_is_besieged_by,null),
			(party_set_slot,'p_town_15',slot_town_initial_faction,0),
			(party_set_slot,'p_town_15',slot_town_scene_flags,0),
			(party_set_slot,'p_town_15',slot_town_reserve_patrol,-1),
			(party_set_slot,'p_town_15',slot_town_spawn_points,2500),
			(party_set_slot,'p_town_15',slot_party_type,spt_city),
			(party_set_slot,'p_town_15',slot_party_food,50000),
			(party_set_slot,'p_town_15',slot_party_icon,'icon_town'),
			(party_set_slot,'p_town_15',slot_party_icon_state,tis_normal),
			(party_set_slot,'p_town_15',slot_party_ai_state,null),
			(party_set_slot,'p_town_15',slot_party_ai_object,null),
			(party_set_slot,'p_town_15',slot_town_accumulated_rents,0),
			(party_set_slot,'p_town_15',slot_town_accumulated_tariffs,0),
			(party_set_slot,'p_town_15',slot_town_current_improvement,null),
			(party_set_slot,'p_town_15',slot_town_improvement_end_hour,null),
			(party_set_slot,'p_town_15',slot_town_housing_level,1),
			(party_set_slot,'p_town_15',slot_town_irrigation_level,1),
			(party_set_slot,'p_town_15',slot_town_mill_level,1),
			(party_set_slot,'p_town_15',slot_town_raided_by,null),
			(party_set_slot,'p_town_15',slot_town_state,sts_normal),
			(party_set_slot,'p_town_15',slot_town_raid_progress,null),
			(party_set_slot,'p_town_15',slot_town_recover_progress,null),
			(party_set_slot,'p_town_15',slot_town_production_bonus,1),
			(party_set_slot,'p_town_15',slot_town_siege_days,0),
			(party_set_slot,'p_town_15',slot_town_reserve_patrol,null),
			(party_set_slot,'p_town_15',slot_town_trade_good_productions_begin,null),
			(party_set_slot,'p_town_15',slot_town_trade_good_temp_productions_begin,null),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_town_15',slot_town_trade_good_price_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_town_15',slot_town_trade_good_abundance_array,'$return'),
			(party_set_slot,'p_town_15',slot_town_tax_rate,100),
			(party_set_slot,'p_town_15',slot_town_shoen,null),
			(party_set_slot,'p_town_15',slot_town_prefecture_array,null),
			(party_set_slot,'p_town_15',slot_town_reinforcements_a,'pt_town_reinforcements_a'),
			(party_set_slot,'p_town_15',slot_town_reinforcements_b,'pt_town_reinforcements_b'),
			(party_set_slot,'p_town_15',slot_town_reinforcements_c,'pt_town_reinforcements_c'),
			(party_set_slot,'p_town_15',slot_town_population,2500),
			(party_set_slot,'p_town_15',slot_town_population_max,10000),
			(party_set_slot,'p_town_15',slot_town_population_growth_factor,1),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_town_15',slot_town_demand_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_town_15',slot_town_storehouse_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_town_15',slot_town_facility_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_town_15',slot_town_surplus_array,'$return'),

			(party_set_slot,'p_town_16',slot_town_center,0),
			(party_set_slot,'p_town_16',slot_town_castle,0),
			(party_set_slot,'p_town_16',slot_town_inn,0),
			(party_set_slot,'p_town_16',slot_town_store,0),
			(party_set_slot,'p_town_16',slot_town_smithy,0),
			(party_set_slot,'p_town_16',slot_town_capital,hikone),
			(party_set_slot,'p_town_16',slot_town_dojo,0),
			(party_set_slot,'p_town_16',slot_town_sensei,-1),
			(party_set_slot,'p_town_16',slot_town_kokujin,'trp_town_16_kokujin'),
			(party_set_slot,'p_town_16',slot_town_shugo,-1),
			(party_set_slot,'p_town_16',slot_town_innkeeper,'trp_town_16_innkeeper'),
			(party_set_slot,'p_town_16',slot_town_weaponsmith,'trp_town_16_weaponsmith'),
			(party_set_slot,'p_town_16',slot_town_armorer,'trp_town_16_armorer'),
			(party_set_slot,'p_town_16',slot_town_merchant,'trp_town_16_merchant'),
			(party_set_slot,'p_town_16',slot_town_broker,null),
			(party_set_slot,'p_town_16',slot_town_moneychanger,null),
			(party_set_slot,'p_town_16',slot_town_fishmonger,'trp_town_16_fishmonger'),
			(party_set_slot,'p_town_16',slot_town_horse_trader,null),
			(party_set_slot,'p_town_16',slot_town_export_good,itm_kyoto_sake),
			(party_set_slot,'p_town_16',slot_town_export_rate,100),
			(party_set_slot,'p_town_16',slot_town_import_good,itm_salt),
			(party_set_slot,'p_town_16',slot_town_import_rate,100),
			(party_set_slot,'p_town_16',slot_town_terrain,ter_lakeside),
			(party_set_slot,'p_town_16',slot_town_size,ct_town),
			(party_set_slot,'p_town_16',slot_town_mercs,'p_town_16_mercs'),
			(party_set_slot,'p_town_16',slot_town_trade_hub,0),
			(party_set_slot,'p_town_16',slot_town_trade_dest,otsu),
			(party_set_slot,'p_town_16',slot_town_trade_month,4),
			(party_set_slot,'p_town_16',slot_town_att_to_player,att_cautious),
			(party_set_slot,'p_town_16',slot_town_player_relation,0),
			(party_set_slot,'p_town_16',slot_town_import_demand,3),
			(party_set_slot,'p_town_16',slot_town_export_demand,3),
			(party_set_slot,'p_town_16',slot_town_demand,0),
			(call_script,'script_town_init_trade_dest','p_town_16',otsu,null,null,null,null,null),
			(party_set_slot,'p_town_16',slot_town_treasury,18000),
			(party_set_slot,'p_town_16',slot_town_garrison_source,'p_town_garrison_source'),
			(party_set_slot,'p_town_16',slot_town_siege_active,0),
			(party_set_slot,'p_town_16',slot_town_under_siege,false),
			(party_set_slot,'p_town_16',slot_town_is_besieged_by,null),
			(party_set_slot,'p_town_16',slot_town_initial_faction,0),
			(party_set_slot,'p_town_16',slot_town_scene_flags,0),
			(party_set_slot,'p_town_16',slot_town_reserve_patrol,-1),
			(party_set_slot,'p_town_16',slot_town_spawn_points,2500),
			(party_set_slot,'p_town_16',slot_party_type,spt_city),
			(party_set_slot,'p_town_16',slot_party_food,50000),
			(party_set_slot,'p_town_16',slot_party_icon,'icon_town'),
			(party_set_slot,'p_town_16',slot_party_icon_state,tis_normal),
			(party_set_slot,'p_town_16',slot_party_ai_state,null),
			(party_set_slot,'p_town_16',slot_party_ai_object,null),
			(party_set_slot,'p_town_16',slot_town_accumulated_rents,0),
			(party_set_slot,'p_town_16',slot_town_accumulated_tariffs,0),
			(party_set_slot,'p_town_16',slot_town_current_improvement,null),
			(party_set_slot,'p_town_16',slot_town_improvement_end_hour,null),
			(party_set_slot,'p_town_16',slot_town_housing_level,1),
			(party_set_slot,'p_town_16',slot_town_irrigation_level,1),
			(party_set_slot,'p_town_16',slot_town_mill_level,1),
			(party_set_slot,'p_town_16',slot_town_raided_by,null),
			(party_set_slot,'p_town_16',slot_town_state,sts_normal),
			(party_set_slot,'p_town_16',slot_town_raid_progress,null),
			(party_set_slot,'p_town_16',slot_town_recover_progress,null),
			(party_set_slot,'p_town_16',slot_town_production_bonus,1),
			(party_set_slot,'p_town_16',slot_town_siege_days,0),
			(party_set_slot,'p_town_16',slot_town_reserve_patrol,null),
			(party_set_slot,'p_town_16',slot_town_trade_good_productions_begin,null),
			(party_set_slot,'p_town_16',slot_town_trade_good_temp_productions_begin,null),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_town_16',slot_town_trade_good_price_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_town_16',slot_town_trade_good_abundance_array,'$return'),
			(party_set_slot,'p_town_16',slot_town_tax_rate,100),
			(party_set_slot,'p_town_16',slot_town_shoen,null),
			(party_set_slot,'p_town_16',slot_town_prefecture_array,null),
			(party_set_slot,'p_town_16',slot_town_reinforcements_a,'pt_town_reinforcements_a'),
			(party_set_slot,'p_town_16',slot_town_reinforcements_b,'pt_town_reinforcements_b'),
			(party_set_slot,'p_town_16',slot_town_reinforcements_c,'pt_town_reinforcements_c'),
			(party_set_slot,'p_town_16',slot_town_population,2500),
			(party_set_slot,'p_town_16',slot_town_population_max,10000),
			(party_set_slot,'p_town_16',slot_town_population_growth_factor,1),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_town_16',slot_town_demand_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_town_16',slot_town_storehouse_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_town_16',slot_town_facility_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_town_16',slot_town_surplus_array,'$return'),

			(party_set_slot,'p_town_17',slot_town_center,0),
			(party_set_slot,'p_town_17',slot_town_castle,0),
			(party_set_slot,'p_town_17',slot_town_inn,0),
			(party_set_slot,'p_town_17',slot_town_store,0),
			(party_set_slot,'p_town_17',slot_town_smithy,0),
			(party_set_slot,'p_town_17',slot_town_capital,tsuruga),
			(party_set_slot,'p_town_17',slot_town_dojo,0),
			(party_set_slot,'p_town_17',slot_town_sensei,-1),
			(party_set_slot,'p_town_17',slot_town_kokujin,'trp_town_17_kokujin'),
			(party_set_slot,'p_town_17',slot_town_shugo,-1),
			(party_set_slot,'p_town_17',slot_town_innkeeper,'trp_town_17_innkeeper'),
			(party_set_slot,'p_town_17',slot_town_weaponsmith,'trp_town_17_weaponsmith'),
			(party_set_slot,'p_town_17',slot_town_armorer,'trp_town_17_armorer'),
			(party_set_slot,'p_town_17',slot_town_merchant,'trp_town_17_merchant'),
			(party_set_slot,'p_town_17',slot_town_broker,null),
			(party_set_slot,'p_town_17',slot_town_moneychanger,null),
			(party_set_slot,'p_town_17',slot_town_fishmonger,'trp_town_17_fishmonger'),
			(party_set_slot,'p_town_17',slot_town_horse_trader,null),
			(party_set_slot,'p_town_17',slot_town_export_good,itm_kyoto_sake),
			(party_set_slot,'p_town_17',slot_town_export_rate,100),
			(party_set_slot,'p_town_17',slot_town_import_good,itm_salt),
			(party_set_slot,'p_town_17',slot_town_import_rate,100),
			(party_set_slot,'p_town_17',slot_town_terrain,ter_lakeside),
			(party_set_slot,'p_town_17',slot_town_size,ct_town),
			(party_set_slot,'p_town_17',slot_town_mercs,'p_town_17_mercs'),
			(party_set_slot,'p_town_17',slot_town_trade_hub,0),
			(party_set_slot,'p_town_17',slot_town_trade_dest,imazu),
			(party_set_slot,'p_town_17',slot_town_trade_month,7),
			(party_set_slot,'p_town_17',slot_town_att_to_player,att_cautious),
			(party_set_slot,'p_town_17',slot_town_player_relation,0),
			(party_set_slot,'p_town_17',slot_town_import_demand,3),
			(party_set_slot,'p_town_17',slot_town_export_demand,3),
			(party_set_slot,'p_town_17',slot_town_demand,0),
			(call_script,'script_town_init_trade_dest','p_town_17',imazu,null,null,null,null,null),
			(party_set_slot,'p_town_17',slot_town_treasury,18000),
			(party_set_slot,'p_town_17',slot_town_garrison_source,'p_town_garrison_source'),
			(party_set_slot,'p_town_17',slot_town_siege_active,0),
			(party_set_slot,'p_town_17',slot_town_under_siege,false),
			(party_set_slot,'p_town_17',slot_town_is_besieged_by,null),
			(party_set_slot,'p_town_17',slot_town_initial_faction,0),
			(party_set_slot,'p_town_17',slot_town_scene_flags,0),
			(party_set_slot,'p_town_17',slot_town_reserve_patrol,-1),
			(party_set_slot,'p_town_17',slot_town_spawn_points,2500),
			(party_set_slot,'p_town_17',slot_party_type,spt_city),
			(party_set_slot,'p_town_17',slot_party_food,50000),
			(party_set_slot,'p_town_17',slot_party_icon,'icon_town'),
			(party_set_slot,'p_town_17',slot_party_icon_state,tis_normal),
			(party_set_slot,'p_town_17',slot_party_ai_state,null),
			(party_set_slot,'p_town_17',slot_party_ai_object,null),
			(party_set_slot,'p_town_17',slot_town_accumulated_rents,0),
			(party_set_slot,'p_town_17',slot_town_accumulated_tariffs,0),
			(party_set_slot,'p_town_17',slot_town_current_improvement,null),
			(party_set_slot,'p_town_17',slot_town_improvement_end_hour,null),
			(party_set_slot,'p_town_17',slot_town_housing_level,1),
			(party_set_slot,'p_town_17',slot_town_irrigation_level,1),
			(party_set_slot,'p_town_17',slot_town_mill_level,1),
			(party_set_slot,'p_town_17',slot_town_raided_by,null),
			(party_set_slot,'p_town_17',slot_town_state,sts_normal),
			(party_set_slot,'p_town_17',slot_town_raid_progress,null),
			(party_set_slot,'p_town_17',slot_town_recover_progress,null),
			(party_set_slot,'p_town_17',slot_town_production_bonus,1),
			(party_set_slot,'p_town_17',slot_town_siege_days,0),
			(party_set_slot,'p_town_17',slot_town_reserve_patrol,null),
			(party_set_slot,'p_town_17',slot_town_trade_good_productions_begin,null),
			(party_set_slot,'p_town_17',slot_town_trade_good_temp_productions_begin,null),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_town_17',slot_town_trade_good_price_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_town_17',slot_town_trade_good_abundance_array,'$return'),
			(party_set_slot,'p_town_17',slot_town_tax_rate,100),
			(party_set_slot,'p_town_17',slot_town_shoen,null),
			(party_set_slot,'p_town_17',slot_town_prefecture_array,null),
			(party_set_slot,'p_town_17',slot_town_reinforcements_a,'pt_town_reinforcements_a'),
			(party_set_slot,'p_town_17',slot_town_reinforcements_b,'pt_town_reinforcements_b'),
			(party_set_slot,'p_town_17',slot_town_reinforcements_c,'pt_town_reinforcements_c'),
			(party_set_slot,'p_town_17',slot_town_population,2500),
			(party_set_slot,'p_town_17',slot_town_population_max,10000),
			(party_set_slot,'p_town_17',slot_town_population_growth_factor,1),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_town_17',slot_town_demand_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_town_17',slot_town_storehouse_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_town_17',slot_town_facility_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_town_17',slot_town_surplus_array,'$return'),

			(party_set_slot,'p_town_18',slot_town_center,0),
			(party_set_slot,'p_town_18',slot_town_castle,0),
			(party_set_slot,'p_town_18',slot_town_inn,0),
			(party_set_slot,'p_town_18',slot_town_store,0),
			(party_set_slot,'p_town_18',slot_town_smithy,0),
			(party_set_slot,'p_town_18',slot_town_capital,hikone),
			(party_set_slot,'p_town_18',slot_town_dojo,'scn_hikone_dojo'),
			(party_set_slot,'p_town_18',slot_town_sensei,'trp_teruhisa'),
			(party_set_slot,'p_town_18',slot_town_kokujin,'trp_town_18_kokujin'),
			(party_set_slot,'p_town_18',slot_town_shugo,-1),
			(party_set_slot,'p_town_18',slot_town_innkeeper,'trp_town_18_innkeeper'),
			(party_set_slot,'p_town_18',slot_town_weaponsmith,'trp_town_18_weaponsmith'),
			(party_set_slot,'p_town_18',slot_town_armorer,'trp_town_18_armorer'),
			(party_set_slot,'p_town_18',slot_town_merchant,'trp_town_18_merchant'),
			(party_set_slot,'p_town_18',slot_town_broker,'trp_broker_5'),
			(party_set_slot,'p_town_18',slot_town_moneychanger,null),
			(party_set_slot,'p_town_18',slot_town_fishmonger,'trp_town_18_fishmonger'),
			(party_set_slot,'p_town_18',slot_town_horse_trader,null),
			(party_set_slot,'p_town_18',slot_town_export_good,itm_kyoto_sake),
			(party_set_slot,'p_town_18',slot_town_export_rate,100),
			(party_set_slot,'p_town_18',slot_town_import_good,itm_salt),
			(party_set_slot,'p_town_18',slot_town_import_rate,100),
			(party_set_slot,'p_town_18',slot_town_terrain,ter_lakeside),
			(party_set_slot,'p_town_18',slot_town_size,ct_town),
			(party_set_slot,'p_town_18',slot_town_mercs,'p_town_18_mercs'),
			(party_set_slot,'p_town_18',slot_town_trade_hub,0),
			(party_set_slot,'p_town_18',slot_town_trade_dest,azuchi),
			(party_set_slot,'p_town_18',slot_town_trade_month,10),
			(party_set_slot,'p_town_18',slot_town_att_to_player,att_cautious),
			(party_set_slot,'p_town_18',slot_town_player_relation,0),
			(party_set_slot,'p_town_18',slot_town_import_demand,3),
			(party_set_slot,'p_town_18',slot_town_export_demand,3),
			(party_set_slot,'p_town_18',slot_town_demand,0),
			(call_script,'script_town_init_trade_dest','p_town_18',azuchi,null,null,null,null,null),
			(party_set_slot,'p_town_18',slot_town_treasury,18000),
			(party_set_slot,'p_town_18',slot_town_garrison_source,'p_town_garrison_source'),
			(party_set_slot,'p_town_18',slot_town_siege_active,0),
			(party_set_slot,'p_town_18',slot_town_under_siege,false),
			(party_set_slot,'p_town_18',slot_town_is_besieged_by,null),
			(party_set_slot,'p_town_18',slot_town_initial_faction,0),
			(party_set_slot,'p_town_18',slot_town_scene_flags,0),
			(party_set_slot,'p_town_18',slot_town_reserve_patrol,-1),
			(party_set_slot,'p_town_18',slot_town_spawn_points,2500),
			(party_set_slot,'p_town_18',slot_party_type,spt_city),
			(party_set_slot,'p_town_18',slot_party_food,50000),
			(party_set_slot,'p_town_18',slot_party_icon,'icon_town'),
			(party_set_slot,'p_town_18',slot_party_icon_state,tis_normal),
			(party_set_slot,'p_town_18',slot_party_ai_state,null),
			(party_set_slot,'p_town_18',slot_party_ai_object,null),
			(party_set_slot,'p_town_18',slot_town_accumulated_rents,0),
			(party_set_slot,'p_town_18',slot_town_accumulated_tariffs,0),
			(party_set_slot,'p_town_18',slot_town_current_improvement,null),
			(party_set_slot,'p_town_18',slot_town_improvement_end_hour,null),
			(party_set_slot,'p_town_18',slot_town_housing_level,1),
			(party_set_slot,'p_town_18',slot_town_irrigation_level,1),
			(party_set_slot,'p_town_18',slot_town_mill_level,1),
			(party_set_slot,'p_town_18',slot_town_raided_by,null),
			(party_set_slot,'p_town_18',slot_town_state,sts_normal),
			(party_set_slot,'p_town_18',slot_town_raid_progress,null),
			(party_set_slot,'p_town_18',slot_town_recover_progress,null),
			(party_set_slot,'p_town_18',slot_town_production_bonus,1),
			(party_set_slot,'p_town_18',slot_town_siege_days,0),
			(party_set_slot,'p_town_18',slot_town_reserve_patrol,null),
			(party_set_slot,'p_town_18',slot_town_trade_good_productions_begin,null),
			(party_set_slot,'p_town_18',slot_town_trade_good_temp_productions_begin,null),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_town_18',slot_town_trade_good_price_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_town_18',slot_town_trade_good_abundance_array,'$return'),
			(party_set_slot,'p_town_18',slot_town_tax_rate,100),
			(party_set_slot,'p_town_18',slot_town_shoen,null),
			(party_set_slot,'p_town_18',slot_town_prefecture_array,null),
			(party_set_slot,'p_town_18',slot_town_reinforcements_a,'pt_town_reinforcements_a'),
			(party_set_slot,'p_town_18',slot_town_reinforcements_b,'pt_town_reinforcements_b'),
			(party_set_slot,'p_town_18',slot_town_reinforcements_c,'pt_town_reinforcements_c'),
			(party_set_slot,'p_town_18',slot_town_population,2500),
			(party_set_slot,'p_town_18',slot_town_population_max,10000),
			(party_set_slot,'p_town_18',slot_town_population_growth_factor,1),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_town_18',slot_town_demand_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_town_18',slot_town_storehouse_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_town_18',slot_town_facility_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_town_18',slot_town_surplus_array,'$return'),

			(party_set_slot,'p_town_19',slot_town_center,0),
			(party_set_slot,'p_town_19',slot_town_castle,0),
			(party_set_slot,'p_town_19',slot_town_inn,0),
			(party_set_slot,'p_town_19',slot_town_store,0),
			(party_set_slot,'p_town_19',slot_town_smithy,0),
			(party_set_slot,'p_town_19',slot_town_capital,miyazu),
			(party_set_slot,'p_town_19',slot_town_dojo,0),
			(party_set_slot,'p_town_19',slot_town_sensei,-1),
			(party_set_slot,'p_town_19',slot_town_kokujin,'trp_town_19_kokujin'),
			(party_set_slot,'p_town_19',slot_town_shugo,'trp_miyazu_shugo'),
			(party_set_slot,'p_town_19',slot_town_innkeeper,'trp_town_19_innkeeper'),
			(party_set_slot,'p_town_19',slot_town_weaponsmith,'trp_town_19_weaponsmith'),
			(party_set_slot,'p_town_19',slot_town_armorer,'trp_town_19_armorer'),
			(party_set_slot,'p_town_19',slot_town_merchant,'trp_town_19_merchant'),
			(party_set_slot,'p_town_19',slot_town_broker,'trp_broker_14'),
			(party_set_slot,'p_town_19',slot_town_moneychanger,null),
			(party_set_slot,'p_town_19',slot_town_fishmonger,'trp_town_19_fishmonger'),
			(party_set_slot,'p_town_19',slot_town_horse_trader,null),
			(party_set_slot,'p_town_19',slot_town_export_good,itm_kyoto_sake),
			(party_set_slot,'p_town_19',slot_town_export_rate,100),
			(party_set_slot,'p_town_19',slot_town_import_good,itm_salt),
			(party_set_slot,'p_town_19',slot_town_import_rate,100),
			(party_set_slot,'p_town_19',slot_town_terrain,ter_seaside),
			(party_set_slot,'p_town_19',slot_town_size,ct_town),
			(party_set_slot,'p_town_19',slot_town_mercs,'p_town_19_mercs'),
			(party_set_slot,'p_town_19',slot_town_trade_hub,0),
			(party_set_slot,'p_town_19',slot_town_trade_dest,fukuchiyama),
			(party_set_slot,'p_town_19',slot_town_trade_month,4),
			(party_set_slot,'p_town_19',slot_town_att_to_player,att_cautious),
			(party_set_slot,'p_town_19',slot_town_player_relation,0),
			(party_set_slot,'p_town_19',slot_town_import_demand,3),
			(party_set_slot,'p_town_19',slot_town_export_demand,3),
			(party_set_slot,'p_town_19',slot_town_demand,0),
			(call_script,'script_town_init_trade_dest','p_town_19',fukuchiyama,null,null,null,null,null),
			(party_set_slot,'p_town_19',slot_town_treasury,18000),
			(party_set_slot,'p_town_19',slot_town_garrison_source,'p_town_garrison_source'),
			(party_set_slot,'p_town_19',slot_town_siege_active,0),
			(party_set_slot,'p_town_19',slot_town_under_siege,false),
			(party_set_slot,'p_town_19',slot_town_is_besieged_by,null),
			(party_set_slot,'p_town_19',slot_town_initial_faction,0),
			(party_set_slot,'p_town_19',slot_town_scene_flags,0),
			(party_set_slot,'p_town_19',slot_town_reserve_patrol,-1),
			(party_set_slot,'p_town_19',slot_town_spawn_points,2500),
			(party_set_slot,'p_town_19',slot_party_type,spt_city),
			(party_set_slot,'p_town_19',slot_party_food,50000),
			(party_set_slot,'p_town_19',slot_party_icon,'icon_town'),
			(party_set_slot,'p_town_19',slot_party_icon_state,tis_normal),
			(party_set_slot,'p_town_19',slot_party_ai_state,null),
			(party_set_slot,'p_town_19',slot_party_ai_object,null),
			(party_set_slot,'p_town_19',slot_town_accumulated_rents,0),
			(party_set_slot,'p_town_19',slot_town_accumulated_tariffs,0),
			(party_set_slot,'p_town_19',slot_town_current_improvement,null),
			(party_set_slot,'p_town_19',slot_town_improvement_end_hour,null),
			(party_set_slot,'p_town_19',slot_town_housing_level,1),
			(party_set_slot,'p_town_19',slot_town_irrigation_level,1),
			(party_set_slot,'p_town_19',slot_town_mill_level,1),
			(party_set_slot,'p_town_19',slot_town_raided_by,null),
			(party_set_slot,'p_town_19',slot_town_state,sts_normal),
			(party_set_slot,'p_town_19',slot_town_raid_progress,null),
			(party_set_slot,'p_town_19',slot_town_recover_progress,null),
			(party_set_slot,'p_town_19',slot_town_production_bonus,1),
			(party_set_slot,'p_town_19',slot_town_siege_days,0),
			(party_set_slot,'p_town_19',slot_town_reserve_patrol,null),
			(party_set_slot,'p_town_19',slot_town_trade_good_productions_begin,null),
			(party_set_slot,'p_town_19',slot_town_trade_good_temp_productions_begin,null),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_town_19',slot_town_trade_good_price_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_town_19',slot_town_trade_good_abundance_array,'$return'),
			(party_set_slot,'p_town_19',slot_town_tax_rate,100),
			(party_set_slot,'p_town_19',slot_town_shoen,null),
			(party_set_slot,'p_town_19',slot_town_prefecture_array,null),
			(party_set_slot,'p_town_19',slot_town_reinforcements_a,'pt_town_reinforcements_a'),
			(party_set_slot,'p_town_19',slot_town_reinforcements_b,'pt_town_reinforcements_b'),
			(party_set_slot,'p_town_19',slot_town_reinforcements_c,'pt_town_reinforcements_c'),
			(party_set_slot,'p_town_19',slot_town_population,2500),
			(party_set_slot,'p_town_19',slot_town_population_max,10000),
			(party_set_slot,'p_town_19',slot_town_population_growth_factor,1),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_town_19',slot_town_demand_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_town_19',slot_town_storehouse_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_town_19',slot_town_facility_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_town_19',slot_town_surplus_array,'$return'),

			(party_set_slot,'p_town_20',slot_town_center,0),
			(party_set_slot,'p_town_20',slot_town_castle,0),
			(party_set_slot,'p_town_20',slot_town_inn,0),
			(party_set_slot,'p_town_20',slot_town_store,0),
			(party_set_slot,'p_town_20',slot_town_smithy,0),
			(party_set_slot,'p_town_20',slot_town_capital,hidaka),
			(party_set_slot,'p_town_20',slot_town_dojo,0),
			(party_set_slot,'p_town_20',slot_town_sensei,-1),
			(party_set_slot,'p_town_20',slot_town_kokujin,'trp_town_20_kokujin'),
			(party_set_slot,'p_town_20',slot_town_shugo,'trp_hidaka_shugo'),
			(party_set_slot,'p_town_20',slot_town_innkeeper,'trp_town_20_innkeeper'),
			(party_set_slot,'p_town_20',slot_town_weaponsmith,'trp_town_20_weaponsmith'),
			(party_set_slot,'p_town_20',slot_town_armorer,'trp_town_20_armorer'),
			(party_set_slot,'p_town_20',slot_town_merchant,'trp_town_20_merchant'),
			(party_set_slot,'p_town_20',slot_town_broker,'trp_broker_9'),
			(party_set_slot,'p_town_20',slot_town_moneychanger,null),
			(party_set_slot,'p_town_20',slot_town_fishmonger,'trp_town_20_fishmonger'),
			(party_set_slot,'p_town_20',slot_town_horse_trader,null),
			(party_set_slot,'p_town_20',slot_town_export_good,itm_kyoto_sake),
			(party_set_slot,'p_town_20',slot_town_export_rate,100),
			(party_set_slot,'p_town_20',slot_town_import_good,itm_salt),
			(party_set_slot,'p_town_20',slot_town_import_rate,100),
			(party_set_slot,'p_town_20',slot_town_terrain,ter_low_valley),
			(party_set_slot,'p_town_20',slot_town_size,ct_town),
			(party_set_slot,'p_town_20',slot_town_mercs,'p_town_20_mercs'),
			(party_set_slot,'p_town_20',slot_town_trade_hub,1),
			(party_set_slot,'p_town_20',slot_town_trade_dest,-1),
			(party_set_slot,'p_town_20',slot_town_trade_month,7),
			(party_set_slot,'p_town_20',slot_town_att_to_player,att_cautious),
			(party_set_slot,'p_town_20',slot_town_player_relation,0),
			(party_set_slot,'p_town_20',slot_town_import_demand,3),
			(party_set_slot,'p_town_20',slot_town_export_demand,3),
			(party_set_slot,'p_town_20',slot_town_demand,0),
			(call_script,'script_town_init_trade_dest','p_town_20',kameyama,null,null,null,null,null),
			(party_set_slot,'p_town_20',slot_town_treasury,18000),
			(party_set_slot,'p_town_20',slot_town_garrison_source,'p_town_garrison_source'),
			(party_set_slot,'p_town_20',slot_town_siege_active,0),
			(party_set_slot,'p_town_20',slot_town_under_siege,false),
			(party_set_slot,'p_town_20',slot_town_is_besieged_by,null),
			(party_set_slot,'p_town_20',slot_town_initial_faction,0),
			(party_set_slot,'p_town_20',slot_town_scene_flags,0),
			(party_set_slot,'p_town_20',slot_town_reserve_patrol,-1),
			(party_set_slot,'p_town_20',slot_town_spawn_points,2500),
			(party_set_slot,'p_town_20',slot_party_type,spt_city),
			(party_set_slot,'p_town_20',slot_party_food,50000),
			(party_set_slot,'p_town_20',slot_party_icon,'icon_town'),
			(party_set_slot,'p_town_20',slot_party_icon_state,tis_normal),
			(party_set_slot,'p_town_20',slot_party_ai_state,null),
			(party_set_slot,'p_town_20',slot_party_ai_object,null),
			(party_set_slot,'p_town_20',slot_town_accumulated_rents,0),
			(party_set_slot,'p_town_20',slot_town_accumulated_tariffs,0),
			(party_set_slot,'p_town_20',slot_town_current_improvement,null),
			(party_set_slot,'p_town_20',slot_town_improvement_end_hour,null),
			(party_set_slot,'p_town_20',slot_town_housing_level,1),
			(party_set_slot,'p_town_20',slot_town_irrigation_level,1),
			(party_set_slot,'p_town_20',slot_town_mill_level,1),
			(party_set_slot,'p_town_20',slot_town_raided_by,null),
			(party_set_slot,'p_town_20',slot_town_state,sts_normal),
			(party_set_slot,'p_town_20',slot_town_raid_progress,null),
			(party_set_slot,'p_town_20',slot_town_recover_progress,null),
			(party_set_slot,'p_town_20',slot_town_production_bonus,1),
			(party_set_slot,'p_town_20',slot_town_siege_days,0),
			(party_set_slot,'p_town_20',slot_town_reserve_patrol,null),
			(party_set_slot,'p_town_20',slot_town_trade_good_productions_begin,null),
			(party_set_slot,'p_town_20',slot_town_trade_good_temp_productions_begin,null),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_town_20',slot_town_trade_good_price_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_town_20',slot_town_trade_good_abundance_array,'$return'),
			(party_set_slot,'p_town_20',slot_town_tax_rate,100),
			(party_set_slot,'p_town_20',slot_town_shoen,null),
			(party_set_slot,'p_town_20',slot_town_prefecture_array,null),
			(party_set_slot,'p_town_20',slot_town_reinforcements_a,'pt_town_reinforcements_a'),
			(party_set_slot,'p_town_20',slot_town_reinforcements_b,'pt_town_reinforcements_b'),
			(party_set_slot,'p_town_20',slot_town_reinforcements_c,'pt_town_reinforcements_c'),
			(party_set_slot,'p_town_20',slot_town_population,2500),
			(party_set_slot,'p_town_20',slot_town_population_max,10000),
			(party_set_slot,'p_town_20',slot_town_population_growth_factor,1),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_town_20',slot_town_demand_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_town_20',slot_town_storehouse_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_town_20',slot_town_facility_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_town_20',slot_town_surplus_array,'$return'),

			(party_set_slot,'p_village_1',slot_town_center,'scn_village'),
			(party_set_slot,'p_village_1',slot_town_castle,0),
			(party_set_slot,'p_village_1',slot_town_inn,0),
			(party_set_slot,'p_village_1',slot_town_store,0),
			(party_set_slot,'p_village_1',slot_town_smithy,0),
			(party_set_slot,'p_village_1',slot_town_capital,hyogo),
			(party_set_slot,'p_village_1',slot_town_dojo,0),
			(party_set_slot,'p_village_1',slot_town_sensei,-1),
			(party_set_slot,'p_village_1',slot_town_kokujin,'trp_village_1_kokujin'),
			(party_set_slot,'p_village_1',slot_town_innkeeper,'trp_village_1_innkeeper'),
			(party_set_slot,'p_village_1',slot_town_merchant,'trp_village_1_merchant'),
			(party_set_slot,'p_village_1',slot_town_broker,null),
			(party_set_slot,'p_village_1',slot_town_moneychanger,null),
			(party_set_slot,'p_village_1',slot_town_fishmonger,'trp_village_1_fishmonger'),
			(party_set_slot,'p_village_1',slot_town_horse_trader,null),
			(party_set_slot,'p_village_1',slot_town_export_good,itm_kyoto_sake),
			(party_set_slot,'p_village_1',slot_town_export_rate,100),
			(party_set_slot,'p_village_1',slot_town_import_good,itm_salt),
			(party_set_slot,'p_village_1',slot_town_import_rate,100),
			(party_set_slot,'p_village_1',slot_town_terrain,ter_lowland),
			(party_set_slot,'p_village_1',slot_town_size,ct_large_village),
			(party_set_slot,'p_village_1',slot_town_mercs,'p_village_1_mercs'),
			(party_set_slot,'p_village_1',slot_town_trade_hub,0),
			(call_script,'script_town_init_trade_dest','p_village_1',hyogo,null,null,null,null,null),
			(party_set_slot,'p_village_1',slot_town_trade_month,7),
			(party_set_slot,'p_village_1',slot_town_att_to_player,att_cautious),
			(party_set_slot,'p_village_1',slot_town_player_relation,0),
			(party_set_slot,'p_village_1',slot_town_import_demand,3),
			(party_set_slot,'p_village_1',slot_town_export_demand,3),
			(party_set_slot,'p_village_1',slot_town_demand,0),
			(party_set_slot,'p_village_1',slot_town_treasury,3600),
			(party_set_slot,'p_village_1',slot_town_garrison_source,'p_village_garrison_source'),
			(party_set_slot,'p_village_1',slot_town_siege_active,0),
			(party_set_slot,'p_village_1',slot_town_under_siege,false),
			(party_set_slot,'p_village_1',slot_town_is_besieged_by,null),
			(party_set_slot,'p_village_1',slot_town_initial_faction,0),
			(party_set_slot,'p_village_1',slot_town_scene_flags,0),
			(party_set_slot,'p_village_1',slot_town_reserve_patrol,-1),
			(party_set_slot,'p_village_1',slot_town_spawn_points,1000),
			(party_set_slot,'p_village_1',slot_party_type,spt_city),
			(party_set_slot,'p_village_1',slot_party_food,5000),
			(party_set_slot,'p_village_1',slot_party_icon,'icon_village'),
			(party_set_slot,'p_village_1',slot_party_icon_state,tis_normal),
			(party_set_slot,'p_village_1',slot_party_ai_state,null),
			(party_set_slot,'p_village_1',slot_party_ai_object,null),
			(party_set_slot,'p_village_1',slot_town_accumulated_rents,0),
			(party_set_slot,'p_village_1',slot_town_accumulated_tariffs,0),
			(party_set_slot,'p_village_1',slot_town_current_improvement,null),
			(party_set_slot,'p_village_1',slot_town_improvement_end_hour,null),
			(party_set_slot,'p_village_1',slot_town_housing_level,1),
			(party_set_slot,'p_village_1',slot_town_irrigation_level,1),
			(party_set_slot,'p_village_1',slot_town_mill_level,1),
			(party_set_slot,'p_village_1',slot_town_raided_by,null),
			(party_set_slot,'p_village_1',slot_town_state,sts_normal),
			(party_set_slot,'p_village_1',slot_town_raid_progress,null),
			(party_set_slot,'p_village_1',slot_town_recover_progress,null),
			(party_set_slot,'p_village_1',slot_town_production_bonus,1),
			(party_set_slot,'p_village_1',slot_town_siege_days,0),
			(party_set_slot,'p_village_1',slot_town_reserve_patrol,null),
			(party_set_slot,'p_village_1',slot_town_trade_good_productions_begin,null),
			(party_set_slot,'p_village_1',slot_town_trade_good_temp_productions_begin,null),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_village_1',slot_town_trade_good_price_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_village_1',slot_town_trade_good_abundance_array,'$return'),
			(party_set_slot,'p_village_1',slot_town_tax_rate,100),
			(party_set_slot,'p_village_1',slot_town_shoen,null),
			(party_set_slot,'p_village_1',slot_town_prefecture_array,null),
			(party_set_slot,'p_village_1',slot_town_reinforcements_a,'pt_village_reinforcements_a'),
			(party_set_slot,'p_village_1',slot_town_reinforcements_b,'pt_village_reinforcements_b'),
			(party_set_slot,'p_village_1',slot_town_reinforcements_c,'pt_village_reinforcements_c'),
			(party_set_slot,'p_village_1',slot_town_population,1000),
			(party_set_slot,'p_village_1',slot_town_population_max,5000),
			(party_set_slot,'p_village_1',slot_town_population_growth_factor,1),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_1',slot_town_demand_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_1',slot_town_storehouse_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_1',slot_town_facility_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_1',slot_town_surplus_array,'$return'),

			(party_set_slot,'p_village_2',slot_town_center,'scn_village'),
			(party_set_slot,'p_village_2',slot_town_castle,0),
			(party_set_slot,'p_village_2',slot_town_inn,0),
			(party_set_slot,'p_village_2',slot_town_store,0),
			(party_set_slot,'p_village_2',slot_town_smithy,0),
			(party_set_slot,'p_village_2',slot_town_capital,hyogo),
			(party_set_slot,'p_village_2',slot_town_dojo,0),
			(party_set_slot,'p_village_2',slot_town_sensei,-1),
			(party_set_slot,'p_village_2',slot_town_kokujin,'trp_village_2_kokujin'),
			(party_set_slot,'p_village_2',slot_town_innkeeper,'trp_village_2_innkeeper'),
			(party_set_slot,'p_village_2',slot_town_merchant,'trp_village_2_merchant'),
			(party_set_slot,'p_village_2',slot_town_broker,null),
			(party_set_slot,'p_village_2',slot_town_moneychanger,null),
			(party_set_slot,'p_village_2',slot_town_fishmonger,'trp_village_2_fishmonger'),
			(party_set_slot,'p_village_2',slot_town_horse_trader,null),
			(party_set_slot,'p_village_2',slot_town_export_good,itm_kyoto_sake),
			(party_set_slot,'p_village_2',slot_town_export_rate,100),
			(party_set_slot,'p_village_2',slot_town_import_good,itm_salt),
			(party_set_slot,'p_village_2',slot_town_import_rate,100),
			(party_set_slot,'p_village_2',slot_town_terrain,ter_low_valley),
			(party_set_slot,'p_village_2',slot_town_size,ct_large_village),
			(party_set_slot,'p_village_2',slot_town_mercs,'p_village_2_mercs'),
			(party_set_slot,'p_village_2',slot_town_trade_hub,0),
			(call_script,'script_town_init_trade_dest','p_village_2',hyogo,null,null,null,null,null),
			(party_set_slot,'p_village_2',slot_town_trade_month,7),
			(party_set_slot,'p_village_2',slot_town_att_to_player,att_cautious),
			(party_set_slot,'p_village_2',slot_town_player_relation,0),
			(party_set_slot,'p_village_2',slot_town_import_demand,3),
			(party_set_slot,'p_village_2',slot_town_export_demand,3),
			(party_set_slot,'p_village_2',slot_town_demand,0),
			(party_set_slot,'p_village_2',slot_town_treasury,3600),
			(party_set_slot,'p_village_2',slot_town_garrison_source,'p_village_garrison_source'),
			(party_set_slot,'p_village_2',slot_town_siege_active,0),
			(party_set_slot,'p_village_2',slot_town_under_siege,false),
			(party_set_slot,'p_village_2',slot_town_is_besieged_by,null),
			(party_set_slot,'p_village_2',slot_town_initial_faction,0),
			(party_set_slot,'p_village_2',slot_town_scene_flags,0),
			(party_set_slot,'p_village_2',slot_town_reserve_patrol,-1),
			(party_set_slot,'p_village_2',slot_town_spawn_points,1000),
			(party_set_slot,'p_village_2',slot_party_type,spt_city),
			(party_set_slot,'p_village_2',slot_party_food,5000),
			(party_set_slot,'p_village_2',slot_party_icon,'icon_village'),
			(party_set_slot,'p_village_2',slot_party_icon_state,tis_normal),
			(party_set_slot,'p_village_2',slot_party_ai_state,null),
			(party_set_slot,'p_village_2',slot_party_ai_object,null),
			(party_set_slot,'p_village_2',slot_town_accumulated_rents,0),
			(party_set_slot,'p_village_2',slot_town_accumulated_tariffs,0),
			(party_set_slot,'p_village_2',slot_town_current_improvement,null),
			(party_set_slot,'p_village_2',slot_town_improvement_end_hour,null),
			(party_set_slot,'p_village_2',slot_town_housing_level,1),
			(party_set_slot,'p_village_2',slot_town_irrigation_level,1),
			(party_set_slot,'p_village_2',slot_town_mill_level,1),
			(party_set_slot,'p_village_2',slot_town_raided_by,null),
			(party_set_slot,'p_village_2',slot_town_state,sts_normal),
			(party_set_slot,'p_village_2',slot_town_raid_progress,null),
			(party_set_slot,'p_village_2',slot_town_recover_progress,null),
			(party_set_slot,'p_village_2',slot_town_production_bonus,1),
			(party_set_slot,'p_village_2',slot_town_siege_days,0),
			(party_set_slot,'p_village_2',slot_town_reserve_patrol,null),
			(party_set_slot,'p_village_2',slot_town_trade_good_productions_begin,null),
			(party_set_slot,'p_village_2',slot_town_trade_good_temp_productions_begin,null),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_village_2',slot_town_trade_good_price_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_village_2',slot_town_trade_good_abundance_array,'$return'),
			(party_set_slot,'p_village_2',slot_town_tax_rate,100),
			(party_set_slot,'p_village_2',slot_town_shoen,null),
			(party_set_slot,'p_village_2',slot_town_prefecture_array,null),
			(party_set_slot,'p_village_2',slot_town_reinforcements_a,'pt_village_reinforcements_a'),
			(party_set_slot,'p_village_2',slot_town_reinforcements_b,'pt_village_reinforcements_b'),
			(party_set_slot,'p_village_2',slot_town_reinforcements_c,'pt_village_reinforcements_c'),
			(party_set_slot,'p_village_2',slot_town_population,1000),
			(party_set_slot,'p_village_2',slot_town_population_max,5000),
			(party_set_slot,'p_village_2',slot_town_population_growth_factor,1),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_2',slot_town_demand_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_2',slot_town_storehouse_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_2',slot_town_facility_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_2',slot_town_surplus_array,'$return'),

			(party_set_slot,'p_village_3',slot_town_center,'scn_village'),
			(party_set_slot,'p_village_3',slot_town_castle,0),
			(party_set_slot,'p_village_3',slot_town_inn,0),
			(party_set_slot,'p_village_3',slot_town_store,0),
			(party_set_slot,'p_village_3',slot_town_smithy,0),
			(party_set_slot,'p_village_3',slot_town_capital,sakai),
			(party_set_slot,'p_village_3',slot_town_dojo,0),
			(party_set_slot,'p_village_3',slot_town_sensei,-1),
			(party_set_slot,'p_village_3',slot_town_kokujin,'trp_village_3_kokujin'),
			(party_set_slot,'p_village_3',slot_town_innkeeper,'trp_village_3_innkeeper'),
			(party_set_slot,'p_village_3',slot_town_merchant,'trp_village_3_merchant'),
			(party_set_slot,'p_village_3',slot_town_broker,null),
			(party_set_slot,'p_village_3',slot_town_moneychanger,null),
			(party_set_slot,'p_village_3',slot_town_fishmonger,'trp_village_3_fishmonger'),
			(party_set_slot,'p_village_3',slot_town_horse_trader,null),
			(party_set_slot,'p_village_3',slot_town_export_good,itm_kyoto_sake),
			(party_set_slot,'p_village_3',slot_town_export_rate,100),
			(party_set_slot,'p_village_3',slot_town_import_good,itm_salt),
			(party_set_slot,'p_village_3',slot_town_import_rate,100),
			(party_set_slot,'p_village_3',slot_town_terrain,ter_seaside),
			(party_set_slot,'p_village_3',slot_town_size,ct_large_village),
			(party_set_slot,'p_village_3',slot_town_mercs,'p_village_3_mercs'),
			(party_set_slot,'p_village_3',slot_town_trade_hub,0),
			(call_script,'script_town_init_trade_dest','p_village_3',sakai,null,null,null,null,null),
			(party_set_slot,'p_village_3',slot_town_trade_month,4),
			(party_set_slot,'p_village_3',slot_town_att_to_player,att_cautious),
			(party_set_slot,'p_village_3',slot_town_player_relation,0),
			(party_set_slot,'p_village_3',slot_town_import_demand,3),
			(party_set_slot,'p_village_3',slot_town_export_demand,3),
			(party_set_slot,'p_village_3',slot_town_demand,0),
			(party_set_slot,'p_village_3',slot_town_treasury,3600),
			(party_set_slot,'p_village_3',slot_town_garrison_source,'p_village_garrison_source'),
			(party_set_slot,'p_village_3',slot_town_siege_active,0),
			(party_set_slot,'p_village_3',slot_town_under_siege,false),
			(party_set_slot,'p_village_3',slot_town_is_besieged_by,null),
			(party_set_slot,'p_village_3',slot_town_initial_faction,0),
			(party_set_slot,'p_village_3',slot_town_scene_flags,0),
			(party_set_slot,'p_village_3',slot_town_reserve_patrol,-1),
			(party_set_slot,'p_village_3',slot_town_spawn_points,1000),
			(party_set_slot,'p_village_3',slot_party_type,spt_city),
			(party_set_slot,'p_village_3',slot_party_food,5000),
			(party_set_slot,'p_village_3',slot_party_icon,'icon_village'),
			(party_set_slot,'p_village_3',slot_party_icon_state,tis_normal),
			(party_set_slot,'p_village_3',slot_party_ai_state,null),
			(party_set_slot,'p_village_3',slot_party_ai_object,null),
			(party_set_slot,'p_village_3',slot_town_accumulated_rents,0),
			(party_set_slot,'p_village_3',slot_town_accumulated_tariffs,0),
			(party_set_slot,'p_village_3',slot_town_current_improvement,null),
			(party_set_slot,'p_village_3',slot_town_improvement_end_hour,null),
			(party_set_slot,'p_village_3',slot_town_housing_level,1),
			(party_set_slot,'p_village_3',slot_town_irrigation_level,1),
			(party_set_slot,'p_village_3',slot_town_mill_level,1),
			(party_set_slot,'p_village_3',slot_town_raided_by,null),
			(party_set_slot,'p_village_3',slot_town_state,sts_normal),
			(party_set_slot,'p_village_3',slot_town_raid_progress,null),
			(party_set_slot,'p_village_3',slot_town_recover_progress,null),
			(party_set_slot,'p_village_3',slot_town_production_bonus,1),
			(party_set_slot,'p_village_3',slot_town_siege_days,0),
			(party_set_slot,'p_village_3',slot_town_reserve_patrol,null),
			(party_set_slot,'p_village_3',slot_town_trade_good_productions_begin,null),
			(party_set_slot,'p_village_3',slot_town_trade_good_temp_productions_begin,null),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_village_3',slot_town_trade_good_price_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_village_3',slot_town_trade_good_abundance_array,'$return'),
			(party_set_slot,'p_village_3',slot_town_tax_rate,100),
			(party_set_slot,'p_village_3',slot_town_shoen,null),
			(party_set_slot,'p_village_3',slot_town_prefecture_array,null),
			(party_set_slot,'p_village_3',slot_town_reinforcements_a,'pt_village_reinforcements_a'),
			(party_set_slot,'p_village_3',slot_town_reinforcements_b,'pt_village_reinforcements_b'),
			(party_set_slot,'p_village_3',slot_town_reinforcements_c,'pt_village_reinforcements_c'),
			(party_set_slot,'p_village_3',slot_town_population,1000),
			(party_set_slot,'p_village_3',slot_town_population_max,5000),
			(party_set_slot,'p_village_3',slot_town_population_growth_factor,1),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_3',slot_town_demand_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_3',slot_town_storehouse_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_3',slot_town_facility_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_3',slot_town_surplus_array,'$return'),

			(party_set_slot,'p_village_4',slot_town_center,'scn_village'),
			(party_set_slot,'p_village_4',slot_town_castle,0),
			(party_set_slot,'p_village_4',slot_town_inn,0),
			(party_set_slot,'p_village_4',slot_town_store,0),
			(party_set_slot,'p_village_4',slot_town_smithy,0),
			(party_set_slot,'p_village_4',slot_town_capital,haga),
			(party_set_slot,'p_village_4',slot_town_dojo,'scn_haga_dojo'),
			(party_set_slot,'p_village_4',slot_town_sensei,'trp_kiyouji'),
			(party_set_slot,'p_village_4',slot_town_kokujin,'trp_village_4_kokujin'),
			(party_set_slot,'p_village_4',slot_town_innkeeper,'trp_village_4_innkeeper'),
			(party_set_slot,'p_village_4',slot_town_merchant,'trp_village_4_merchant'),
			(party_set_slot,'p_village_4',slot_town_broker,null),
			(party_set_slot,'p_village_4',slot_town_moneychanger,null),
			(party_set_slot,'p_village_4',slot_town_fishmonger,'trp_village_4_fishmonger'),
			(party_set_slot,'p_village_4',slot_town_horse_trader,null),
			(party_set_slot,'p_village_4',slot_town_export_good,itm_kyoto_sake),
			(party_set_slot,'p_village_4',slot_town_export_rate,100),
			(party_set_slot,'p_village_4',slot_town_import_good,itm_salt),
			(party_set_slot,'p_village_4',slot_town_import_rate,100),
			(party_set_slot,'p_village_4',slot_town_terrain,ter_high_valley),
			(party_set_slot,'p_village_4',slot_town_size,ct_small_village),
			(party_set_slot,'p_village_4',slot_town_mercs,'p_village_4_mercs'),
			(party_set_slot,'p_village_4',slot_town_trade_hub,0),
			(call_script,'script_town_init_trade_dest','p_village_4',himeji,null,null,null,null,null),
			(party_set_slot,'p_village_4',slot_town_trade_month,7),
			(party_set_slot,'p_village_4',slot_town_att_to_player,att_cautious),
			(party_set_slot,'p_village_4',slot_town_player_relation,0),
			(party_set_slot,'p_village_4',slot_town_import_demand,3),
			(party_set_slot,'p_village_4',slot_town_export_demand,3),
			(party_set_slot,'p_village_4',slot_town_demand,0),
			(party_set_slot,'p_village_4',slot_town_treasury,3600),
			(party_set_slot,'p_village_4',slot_town_garrison_source,'p_village_garrison_source'),
			(party_set_slot,'p_village_4',slot_town_siege_active,0),
			(party_set_slot,'p_village_4',slot_town_under_siege,false),
			(party_set_slot,'p_village_4',slot_town_is_besieged_by,null),
			(party_set_slot,'p_village_4',slot_town_initial_faction,0),
			(party_set_slot,'p_village_4',slot_town_scene_flags,0),
			(party_set_slot,'p_village_4',slot_town_reserve_patrol,-1),
			(party_set_slot,'p_village_4',slot_town_spawn_points,1000),
			(party_set_slot,'p_village_4',slot_party_type,spt_city),
			(party_set_slot,'p_village_4',slot_party_food,5000),
			(party_set_slot,'p_village_4',slot_party_icon,'icon_village'),
			(party_set_slot,'p_village_4',slot_party_icon_state,tis_normal),
			(party_set_slot,'p_village_4',slot_party_ai_state,null),
			(party_set_slot,'p_village_4',slot_party_ai_object,null),
			(party_set_slot,'p_village_4',slot_town_accumulated_rents,0),
			(party_set_slot,'p_village_4',slot_town_accumulated_tariffs,0),
			(party_set_slot,'p_village_4',slot_town_current_improvement,null),
			(party_set_slot,'p_village_4',slot_town_improvement_end_hour,null),
			(party_set_slot,'p_village_4',slot_town_housing_level,1),
			(party_set_slot,'p_village_4',slot_town_irrigation_level,1),
			(party_set_slot,'p_village_4',slot_town_mill_level,1),
			(party_set_slot,'p_village_4',slot_town_raided_by,null),
			(party_set_slot,'p_village_4',slot_town_state,sts_normal),
			(party_set_slot,'p_village_4',slot_town_raid_progress,null),
			(party_set_slot,'p_village_4',slot_town_recover_progress,null),
			(party_set_slot,'p_village_4',slot_town_production_bonus,1),
			(party_set_slot,'p_village_4',slot_town_siege_days,0),
			(party_set_slot,'p_village_4',slot_town_reserve_patrol,null),
			(party_set_slot,'p_village_4',slot_town_trade_good_productions_begin,null),
			(party_set_slot,'p_village_4',slot_town_trade_good_temp_productions_begin,null),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_village_4',slot_town_trade_good_price_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_village_4',slot_town_trade_good_abundance_array,'$return'),
			(party_set_slot,'p_village_4',slot_town_tax_rate,100),
			(party_set_slot,'p_village_4',slot_town_shoen,null),
			(party_set_slot,'p_village_4',slot_town_prefecture_array,null),
			(party_set_slot,'p_village_4',slot_town_reinforcements_a,'pt_village_reinforcements_a'),
			(party_set_slot,'p_village_4',slot_town_reinforcements_b,'pt_village_reinforcements_b'),
			(party_set_slot,'p_village_4',slot_town_reinforcements_c,'pt_village_reinforcements_c'),
			(party_set_slot,'p_village_4',slot_town_population,1000),
			(party_set_slot,'p_village_4',slot_town_population_max,5000),
			(party_set_slot,'p_village_4',slot_town_population_growth_factor,1),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_4',slot_town_demand_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_4',slot_town_storehouse_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_4',slot_town_facility_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_4',slot_town_surplus_array,'$return'),

			(party_set_slot,'p_village_5',slot_town_center,'scn_village'),
			(party_set_slot,'p_village_5',slot_town_castle,0),
			(party_set_slot,'p_village_5',slot_town_inn,0),
			(party_set_slot,'p_village_5',slot_town_store,0),
			(party_set_slot,'p_village_5',slot_town_smithy,0),
			(party_set_slot,'p_village_5',slot_town_capital,obama),
			(party_set_slot,'p_village_5',slot_town_dojo,0),
			(party_set_slot,'p_village_5',slot_town_sensei,-1),
			(party_set_slot,'p_village_5',slot_town_kokujin,'trp_village_5_kokujin'),
			(party_set_slot,'p_village_5',slot_town_innkeeper,'trp_village_5_innkeeper'),
			(party_set_slot,'p_village_5',slot_town_merchant,'trp_village_5_merchant'),
			(party_set_slot,'p_village_5',slot_town_broker,null),
			(party_set_slot,'p_village_5',slot_town_moneychanger,null),
			(party_set_slot,'p_village_5',slot_town_fishmonger,'trp_village_5_fishmonger'),
			(party_set_slot,'p_village_5',slot_town_horse_trader,null),
			(party_set_slot,'p_village_5',slot_town_export_good,itm_kyoto_sake),
			(party_set_slot,'p_village_5',slot_town_export_rate,100),
			(party_set_slot,'p_village_5',slot_town_import_good,itm_salt),
			(party_set_slot,'p_village_5',slot_town_import_rate,100),
			(party_set_slot,'p_village_5',slot_town_terrain,ter_seaside),
			(party_set_slot,'p_village_5',slot_town_size,ct_large_village),
			(party_set_slot,'p_village_5',slot_town_mercs,'p_village_5_mercs'),
			(party_set_slot,'p_village_5',slot_town_trade_hub,0),
			(call_script,'script_town_init_trade_dest','p_village_5',obama,null,null,null,null,null),
			(party_set_slot,'p_village_5',slot_town_trade_month,10),
			(party_set_slot,'p_village_5',slot_town_att_to_player,att_cautious),
			(party_set_slot,'p_village_5',slot_town_player_relation,0),
			(party_set_slot,'p_village_5',slot_town_import_demand,3),
			(party_set_slot,'p_village_5',slot_town_export_demand,3),
			(party_set_slot,'p_village_5',slot_town_demand,0),
			(party_set_slot,'p_village_5',slot_town_treasury,3600),
			(party_set_slot,'p_village_5',slot_town_garrison_source,'p_village_garrison_source'),
			(party_set_slot,'p_village_5',slot_town_siege_active,0),
			(party_set_slot,'p_village_5',slot_town_under_siege,false),
			(party_set_slot,'p_village_5',slot_town_is_besieged_by,null),
			(party_set_slot,'p_village_5',slot_town_initial_faction,0),
			(party_set_slot,'p_village_5',slot_town_scene_flags,0),
			(party_set_slot,'p_village_5',slot_town_reserve_patrol,-1),
			(party_set_slot,'p_village_5',slot_town_spawn_points,1000),
			(party_set_slot,'p_village_5',slot_party_type,spt_city),
			(party_set_slot,'p_village_5',slot_party_food,5000),
			(party_set_slot,'p_village_5',slot_party_icon,'icon_village'),
			(party_set_slot,'p_village_5',slot_party_icon_state,tis_normal),
			(party_set_slot,'p_village_5',slot_party_ai_state,null),
			(party_set_slot,'p_village_5',slot_party_ai_object,null),
			(party_set_slot,'p_village_5',slot_town_accumulated_rents,0),
			(party_set_slot,'p_village_5',slot_town_accumulated_tariffs,0),
			(party_set_slot,'p_village_5',slot_town_current_improvement,null),
			(party_set_slot,'p_village_5',slot_town_improvement_end_hour,null),
			(party_set_slot,'p_village_5',slot_town_housing_level,1),
			(party_set_slot,'p_village_5',slot_town_irrigation_level,1),
			(party_set_slot,'p_village_5',slot_town_mill_level,1),
			(party_set_slot,'p_village_5',slot_town_raided_by,null),
			(party_set_slot,'p_village_5',slot_town_state,sts_normal),
			(party_set_slot,'p_village_5',slot_town_raid_progress,null),
			(party_set_slot,'p_village_5',slot_town_recover_progress,null),
			(party_set_slot,'p_village_5',slot_town_production_bonus,1),
			(party_set_slot,'p_village_5',slot_town_siege_days,0),
			(party_set_slot,'p_village_5',slot_town_reserve_patrol,null),
			(party_set_slot,'p_village_5',slot_town_trade_good_productions_begin,null),
			(party_set_slot,'p_village_5',slot_town_trade_good_temp_productions_begin,null),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_village_5',slot_town_trade_good_price_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_village_5',slot_town_trade_good_abundance_array,'$return'),
			(party_set_slot,'p_village_5',slot_town_tax_rate,100),
			(party_set_slot,'p_village_5',slot_town_shoen,null),
			(party_set_slot,'p_village_5',slot_town_prefecture_array,null),
			(party_set_slot,'p_village_5',slot_town_reinforcements_a,'pt_village_reinforcements_a'),
			(party_set_slot,'p_village_5',slot_town_reinforcements_b,'pt_village_reinforcements_b'),
			(party_set_slot,'p_village_5',slot_town_reinforcements_c,'pt_village_reinforcements_c'),
			(party_set_slot,'p_village_5',slot_town_population,1000),
			(party_set_slot,'p_village_5',slot_town_population_max,5000),
			(party_set_slot,'p_village_5',slot_town_population_growth_factor,1),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_5',slot_town_demand_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_5',slot_town_storehouse_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_5',slot_town_facility_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_5',slot_town_surplus_array,'$return'),

			(party_set_slot,'p_village_6',slot_town_center,'scn_village'),
			(party_set_slot,'p_village_6',slot_town_castle,0),
			(party_set_slot,'p_village_6',slot_town_inn,0),
			(party_set_slot,'p_village_6',slot_town_store,0),
			(party_set_slot,'p_village_6',slot_town_smithy,0),
			(party_set_slot,'p_village_6',slot_town_capital,hyogo),
			(party_set_slot,'p_village_6',slot_town_dojo,0),
			(party_set_slot,'p_village_6',slot_town_sensei,-1),
			(party_set_slot,'p_village_6',slot_town_kokujin,'trp_village_6_kokujin'),
			(party_set_slot,'p_village_6',slot_town_innkeeper,'trp_village_6_innkeeper'),
			(party_set_slot,'p_village_6',slot_town_merchant,'trp_village_6_merchant'),
			(party_set_slot,'p_village_6',slot_town_broker,null),
			(party_set_slot,'p_village_6',slot_town_moneychanger,null),
			(party_set_slot,'p_village_6',slot_town_fishmonger,'trp_village_6_fishmonger'),
			(party_set_slot,'p_village_6',slot_town_horse_trader,null),
			(party_set_slot,'p_village_6',slot_town_export_good,itm_kyoto_sake),
			(party_set_slot,'p_village_6',slot_town_export_rate,100),
			(party_set_slot,'p_village_6',slot_town_import_good,itm_salt),
			(party_set_slot,'p_village_6',slot_town_import_rate,100),
			(party_set_slot,'p_village_6',slot_town_terrain,ter_high_valley),
			(party_set_slot,'p_village_6',slot_town_size,ct_village),
			(party_set_slot,'p_village_6',slot_town_mercs,'p_village_6_mercs'),
			(party_set_slot,'p_village_6',slot_town_trade_hub,0),
			(call_script,'script_town_init_trade_dest','p_village_6',hyogo,null,null,null,null,null),
			(party_set_slot,'p_village_6',slot_town_trade_month,4),
			(party_set_slot,'p_village_6',slot_town_att_to_player,att_cautious),
			(party_set_slot,'p_village_6',slot_town_player_relation,0),
			(party_set_slot,'p_village_6',slot_town_import_demand,3),
			(party_set_slot,'p_village_6',slot_town_export_demand,3),
			(party_set_slot,'p_village_6',slot_town_demand,0),
			(party_set_slot,'p_village_6',slot_town_treasury,3600),
			(party_set_slot,'p_village_6',slot_town_garrison_source,'p_village_garrison_source'),
			(party_set_slot,'p_village_6',slot_town_siege_active,0),
			(party_set_slot,'p_village_6',slot_town_under_siege,false),
			(party_set_slot,'p_village_6',slot_town_is_besieged_by,null),
			(party_set_slot,'p_village_6',slot_town_initial_faction,0),
			(party_set_slot,'p_village_6',slot_town_scene_flags,0),
			(party_set_slot,'p_village_6',slot_town_reserve_patrol,-1),
			(party_set_slot,'p_village_6',slot_town_spawn_points,1000),
			(party_set_slot,'p_village_6',slot_party_type,spt_city),
			(party_set_slot,'p_village_6',slot_party_food,5000),
			(party_set_slot,'p_village_6',slot_party_icon,'icon_village'),
			(party_set_slot,'p_village_6',slot_party_icon_state,tis_normal),
			(party_set_slot,'p_village_6',slot_party_ai_state,null),
			(party_set_slot,'p_village_6',slot_party_ai_object,null),
			(party_set_slot,'p_village_6',slot_town_accumulated_rents,0),
			(party_set_slot,'p_village_6',slot_town_accumulated_tariffs,0),
			(party_set_slot,'p_village_6',slot_town_current_improvement,null),
			(party_set_slot,'p_village_6',slot_town_improvement_end_hour,null),
			(party_set_slot,'p_village_6',slot_town_housing_level,1),
			(party_set_slot,'p_village_6',slot_town_irrigation_level,1),
			(party_set_slot,'p_village_6',slot_town_mill_level,1),
			(party_set_slot,'p_village_6',slot_town_raided_by,null),
			(party_set_slot,'p_village_6',slot_town_state,sts_normal),
			(party_set_slot,'p_village_6',slot_town_raid_progress,null),
			(party_set_slot,'p_village_6',slot_town_recover_progress,null),
			(party_set_slot,'p_village_6',slot_town_production_bonus,1),
			(party_set_slot,'p_village_6',slot_town_siege_days,0),
			(party_set_slot,'p_village_6',slot_town_reserve_patrol,null),
			(party_set_slot,'p_village_6',slot_town_trade_good_productions_begin,null),
			(party_set_slot,'p_village_6',slot_town_trade_good_temp_productions_begin,null),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_village_6',slot_town_trade_good_price_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_village_6',slot_town_trade_good_abundance_array,'$return'),
			(party_set_slot,'p_village_6',slot_town_tax_rate,100),
			(party_set_slot,'p_village_6',slot_town_shoen,null),
			(party_set_slot,'p_village_6',slot_town_prefecture_array,null),
			(party_set_slot,'p_village_6',slot_town_reinforcements_a,'pt_village_reinforcements_a'),
			(party_set_slot,'p_village_6',slot_town_reinforcements_b,'pt_village_reinforcements_b'),
			(party_set_slot,'p_village_6',slot_town_reinforcements_c,'pt_village_reinforcements_c'),
			(party_set_slot,'p_village_6',slot_town_population,1000),
			(party_set_slot,'p_village_6',slot_town_population_max,5000),
			(party_set_slot,'p_village_6',slot_town_population_growth_factor,1),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_6',slot_town_demand_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_6',slot_town_storehouse_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_6',slot_town_facility_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_6',slot_town_surplus_array,'$return'),

			(party_set_slot,'p_village_7',slot_town_center,'scn_village'),
			(party_set_slot,'p_village_7',slot_town_castle,0),
			(party_set_slot,'p_village_7',slot_town_inn,0),
			(party_set_slot,'p_village_7',slot_town_store,0),
			(party_set_slot,'p_village_7',slot_town_smithy,0),
			(party_set_slot,'p_village_7',slot_town_capital,kakogawa),
			(party_set_slot,'p_village_7',slot_town_dojo,0),
			(party_set_slot,'p_village_7',slot_town_sensei,-1),
			(party_set_slot,'p_village_7',slot_town_kokujin,'trp_village_7_kokujin'),
			(party_set_slot,'p_village_7',slot_town_innkeeper,'trp_village_7_innkeeper'),
			(party_set_slot,'p_village_7',slot_town_merchant,'trp_village_7_merchant'),
			(party_set_slot,'p_village_7',slot_town_broker,null),
			(party_set_slot,'p_village_7',slot_town_moneychanger,null),
			(party_set_slot,'p_village_7',slot_town_fishmonger,'trp_village_7_fishmonger'),
			(party_set_slot,'p_village_7',slot_town_horse_trader,null),
			(party_set_slot,'p_village_7',slot_town_export_good,itm_kyoto_sake),
			(party_set_slot,'p_village_7',slot_town_export_rate,100),
			(party_set_slot,'p_village_7',slot_town_import_good,itm_salt),
			(party_set_slot,'p_village_7',slot_town_import_rate,100),
			(party_set_slot,'p_village_7',slot_town_terrain,ter_low_valley),
			(party_set_slot,'p_village_7',slot_town_size,ct_village),
			(party_set_slot,'p_village_7',slot_town_mercs,'p_village_7_mercs'),
			(party_set_slot,'p_village_7',slot_town_trade_hub,0),
			(call_script,'script_town_init_trade_dest','p_village_7',kakogawa,null,null,null,null,null),
			(party_set_slot,'p_village_7',slot_town_trade_month,7),
			(party_set_slot,'p_village_7',slot_town_att_to_player,att_cautious),
			(party_set_slot,'p_village_7',slot_town_player_relation,0),
			(party_set_slot,'p_village_7',slot_town_import_demand,3),
			(party_set_slot,'p_village_7',slot_town_export_demand,3),
			(party_set_slot,'p_village_7',slot_town_demand,0),
			(party_set_slot,'p_village_7',slot_town_treasury,3600),
			(party_set_slot,'p_village_7',slot_town_garrison_source,'p_village_garrison_source'),
			(party_set_slot,'p_village_7',slot_town_siege_active,0),
			(party_set_slot,'p_village_7',slot_town_under_siege,false),
			(party_set_slot,'p_village_7',slot_town_is_besieged_by,null),
			(party_set_slot,'p_village_7',slot_town_initial_faction,0),
			(party_set_slot,'p_village_7',slot_town_scene_flags,0),
			(party_set_slot,'p_village_7',slot_town_reserve_patrol,-1),
			(party_set_slot,'p_village_7',slot_town_spawn_points,1000),
			(party_set_slot,'p_village_7',slot_party_type,spt_city),
			(party_set_slot,'p_village_7',slot_party_food,5000),
			(party_set_slot,'p_village_7',slot_party_icon,'icon_village'),
			(party_set_slot,'p_village_7',slot_party_icon_state,tis_normal),
			(party_set_slot,'p_village_7',slot_party_ai_state,null),
			(party_set_slot,'p_village_7',slot_party_ai_object,null),
			(party_set_slot,'p_village_7',slot_town_accumulated_rents,0),
			(party_set_slot,'p_village_7',slot_town_accumulated_tariffs,0),
			(party_set_slot,'p_village_7',slot_town_current_improvement,null),
			(party_set_slot,'p_village_7',slot_town_improvement_end_hour,null),
			(party_set_slot,'p_village_7',slot_town_housing_level,1),
			(party_set_slot,'p_village_7',slot_town_irrigation_level,1),
			(party_set_slot,'p_village_7',slot_town_mill_level,1),
			(party_set_slot,'p_village_7',slot_town_raided_by,null),
			(party_set_slot,'p_village_7',slot_town_state,sts_normal),
			(party_set_slot,'p_village_7',slot_town_raid_progress,null),
			(party_set_slot,'p_village_7',slot_town_recover_progress,null),
			(party_set_slot,'p_village_7',slot_town_production_bonus,1),
			(party_set_slot,'p_village_7',slot_town_siege_days,0),
			(party_set_slot,'p_village_7',slot_town_reserve_patrol,null),
			(party_set_slot,'p_village_7',slot_town_trade_good_productions_begin,null),
			(party_set_slot,'p_village_7',slot_town_trade_good_temp_productions_begin,null),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_village_7',slot_town_trade_good_price_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_village_7',slot_town_trade_good_abundance_array,'$return'),
			(party_set_slot,'p_village_7',slot_town_tax_rate,100),
			(party_set_slot,'p_village_7',slot_town_shoen,null),
			(party_set_slot,'p_village_7',slot_town_prefecture_array,null),
			(party_set_slot,'p_village_7',slot_town_reinforcements_a,'pt_village_reinforcements_a'),
			(party_set_slot,'p_village_7',slot_town_reinforcements_b,'pt_village_reinforcements_b'),
			(party_set_slot,'p_village_7',slot_town_reinforcements_c,'pt_village_reinforcements_c'),
			(party_set_slot,'p_village_7',slot_town_population,1000),
			(party_set_slot,'p_village_7',slot_town_population_max,5000),
			(party_set_slot,'p_village_7',slot_town_population_growth_factor,1),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_7',slot_town_demand_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_7',slot_town_storehouse_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_7',slot_town_facility_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_7',slot_town_surplus_array,'$return'),

			(party_set_slot,'p_village_8',slot_town_center,'scn_village'),
			(party_set_slot,'p_village_8',slot_town_castle,0),
			(party_set_slot,'p_village_8',slot_town_inn,0),
			(party_set_slot,'p_village_8',slot_town_store,0),
			(party_set_slot,'p_village_8',slot_town_smithy,0),
			(party_set_slot,'p_village_8',slot_town_capital,himeji),
			(party_set_slot,'p_village_8',slot_town_dojo,0),
			(party_set_slot,'p_village_8',slot_town_sensei,-1),
			(party_set_slot,'p_village_8',slot_town_kokujin,'trp_village_8_kokujin'),
			(party_set_slot,'p_village_8',slot_town_innkeeper,'trp_village_8_innkeeper'),
			(party_set_slot,'p_village_8',slot_town_merchant,'trp_village_8_merchant'),
			(party_set_slot,'p_village_8',slot_town_broker,null),
			(party_set_slot,'p_village_8',slot_town_moneychanger,null),
			(party_set_slot,'p_village_8',slot_town_fishmonger,'trp_village_8_fishmonger'),
			(party_set_slot,'p_village_8',slot_town_horse_trader,null),
			(party_set_slot,'p_village_8',slot_town_export_good,itm_kyoto_sake),
			(party_set_slot,'p_village_8',slot_town_export_rate,100),
			(party_set_slot,'p_village_8',slot_town_import_good,itm_salt),
			(party_set_slot,'p_village_8',slot_town_import_rate,100),
			(party_set_slot,'p_village_8',slot_town_terrain,ter_low_valley),
			(party_set_slot,'p_village_8',slot_town_size,ct_village),
			(party_set_slot,'p_village_8',slot_town_mercs,'p_village_8_mercs'),
			(party_set_slot,'p_village_8',slot_town_trade_hub,0),
			(call_script,'script_town_init_trade_dest','p_village_8',kakogawa,null,null,null,null,null),
			(party_set_slot,'p_village_8',slot_town_trade_month,10),
			(party_set_slot,'p_village_8',slot_town_att_to_player,att_cautious),
			(party_set_slot,'p_village_8',slot_town_player_relation,0),
			(party_set_slot,'p_village_8',slot_town_import_demand,3),
			(party_set_slot,'p_village_8',slot_town_export_demand,3),
			(party_set_slot,'p_village_8',slot_town_demand,0),
			(party_set_slot,'p_village_8',slot_town_treasury,3600),
			(party_set_slot,'p_village_8',slot_town_garrison_source,'p_village_garrison_source'),
			(party_set_slot,'p_village_8',slot_town_siege_active,0),
			(party_set_slot,'p_village_8',slot_town_under_siege,false),
			(party_set_slot,'p_village_8',slot_town_is_besieged_by,null),
			(party_set_slot,'p_village_8',slot_town_initial_faction,0),
			(party_set_slot,'p_village_8',slot_town_scene_flags,0),
			(party_set_slot,'p_village_8',slot_town_reserve_patrol,-1),
			(party_set_slot,'p_village_8',slot_town_spawn_points,1000),
			(party_set_slot,'p_village_8',slot_party_type,spt_city),
			(party_set_slot,'p_village_8',slot_party_food,5000),
			(party_set_slot,'p_village_8',slot_party_icon,'icon_village'),
			(party_set_slot,'p_village_8',slot_party_icon_state,tis_normal),
			(party_set_slot,'p_village_8',slot_party_ai_state,null),
			(party_set_slot,'p_village_8',slot_party_ai_object,null),
			(party_set_slot,'p_village_8',slot_town_accumulated_rents,0),
			(party_set_slot,'p_village_8',slot_town_accumulated_tariffs,0),
			(party_set_slot,'p_village_8',slot_town_current_improvement,null),
			(party_set_slot,'p_village_8',slot_town_improvement_end_hour,null),
			(party_set_slot,'p_village_8',slot_town_housing_level,1),
			(party_set_slot,'p_village_8',slot_town_irrigation_level,1),
			(party_set_slot,'p_village_8',slot_town_mill_level,1),
			(party_set_slot,'p_village_8',slot_town_raided_by,null),
			(party_set_slot,'p_village_8',slot_town_state,sts_normal),
			(party_set_slot,'p_village_8',slot_town_raid_progress,null),
			(party_set_slot,'p_village_8',slot_town_recover_progress,null),
			(party_set_slot,'p_village_8',slot_town_production_bonus,1),
			(party_set_slot,'p_village_8',slot_town_siege_days,0),
			(party_set_slot,'p_village_8',slot_town_reserve_patrol,null),
			(party_set_slot,'p_village_8',slot_town_trade_good_productions_begin,null),
			(party_set_slot,'p_village_8',slot_town_trade_good_temp_productions_begin,null),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_village_8',slot_town_trade_good_price_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_village_8',slot_town_trade_good_abundance_array,'$return'),
			(party_set_slot,'p_village_8',slot_town_tax_rate,100),
			(party_set_slot,'p_village_8',slot_town_shoen,null),
			(party_set_slot,'p_village_8',slot_town_prefecture_array,null),
			(party_set_slot,'p_village_8',slot_town_reinforcements_a,'pt_village_reinforcements_a'),
			(party_set_slot,'p_village_8',slot_town_reinforcements_b,'pt_village_reinforcements_b'),
			(party_set_slot,'p_village_8',slot_town_reinforcements_c,'pt_village_reinforcements_c'),
			(party_set_slot,'p_village_8',slot_town_population,1000),
			(party_set_slot,'p_village_8',slot_town_population_max,5000),
			(party_set_slot,'p_village_8',slot_town_population_growth_factor,1),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_8',slot_town_demand_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_8',slot_town_storehouse_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_8',slot_town_facility_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_8',slot_town_surplus_array,'$return'),

			(party_set_slot,'p_village_9',slot_town_center,'scn_village'),
			(party_set_slot,'p_village_9',slot_town_castle,0),
			(party_set_slot,'p_village_9',slot_town_inn,0),
			(party_set_slot,'p_village_9',slot_town_store,0),
			(party_set_slot,'p_village_9',slot_town_smithy,0),
			(party_set_slot,'p_village_9',slot_town_capital,himeji),
			(party_set_slot,'p_village_9',slot_town_dojo,0),
			(party_set_slot,'p_village_9',slot_town_sensei,-1),
			(party_set_slot,'p_village_9',slot_town_kokujin,'trp_village_9_kokujin'),
			(party_set_slot,'p_village_9',slot_town_innkeeper,'trp_village_9_innkeeper'),
			(party_set_slot,'p_village_9',slot_town_merchant,'trp_village_9_merchant'),
			(party_set_slot,'p_village_9',slot_town_broker,null),
			(party_set_slot,'p_village_9',slot_town_moneychanger,null),
			(party_set_slot,'p_village_9',slot_town_fishmonger,'trp_village_9_fishmonger'),
			(party_set_slot,'p_village_9',slot_town_horse_trader,null),
			(party_set_slot,'p_village_9',slot_town_export_good,itm_kyoto_sake),
			(party_set_slot,'p_village_9',slot_town_export_rate,100),
			(party_set_slot,'p_village_9',slot_town_import_good,itm_salt),
			(party_set_slot,'p_village_9',slot_town_import_rate,100),
			(party_set_slot,'p_village_9',slot_town_terrain,ter_high_valley),
			(party_set_slot,'p_village_9',slot_town_size,ct_village),
			(party_set_slot,'p_village_9',slot_town_mercs,'p_village_9_mercs'),
			(party_set_slot,'p_village_9',slot_town_trade_hub,0),
			(call_script,'script_town_init_trade_dest','p_village_9',himeji,null,null,null,null,null),
			(party_set_slot,'p_village_9',slot_town_trade_month,4),
			(party_set_slot,'p_village_9',slot_town_att_to_player,att_cautious),
			(party_set_slot,'p_village_9',slot_town_player_relation,0),
			(party_set_slot,'p_village_9',slot_town_import_demand,3),
			(party_set_slot,'p_village_9',slot_town_export_demand,3),
			(party_set_slot,'p_village_9',slot_town_demand,0),
			(party_set_slot,'p_village_9',slot_town_treasury,3600),
			(party_set_slot,'p_village_9',slot_town_garrison_source,'p_village_garrison_source'),
			(party_set_slot,'p_village_9',slot_town_siege_active,0),
			(party_set_slot,'p_village_9',slot_town_under_siege,false),
			(party_set_slot,'p_village_9',slot_town_is_besieged_by,null),
			(party_set_slot,'p_village_9',slot_town_initial_faction,0),
			(party_set_slot,'p_village_9',slot_town_scene_flags,0),
			(party_set_slot,'p_village_9',slot_town_reserve_patrol,-1),
			(party_set_slot,'p_village_9',slot_town_spawn_points,1000),
			(party_set_slot,'p_village_9',slot_party_type,spt_city),
			(party_set_slot,'p_village_9',slot_party_food,5000),
			(party_set_slot,'p_village_9',slot_party_icon,'icon_village'),
			(party_set_slot,'p_village_9',slot_party_icon_state,tis_normal),
			(party_set_slot,'p_village_9',slot_party_ai_state,null),
			(party_set_slot,'p_village_9',slot_party_ai_object,null),
			(party_set_slot,'p_village_9',slot_town_accumulated_rents,0),
			(party_set_slot,'p_village_9',slot_town_accumulated_tariffs,0),
			(party_set_slot,'p_village_9',slot_town_current_improvement,null),
			(party_set_slot,'p_village_9',slot_town_improvement_end_hour,null),
			(party_set_slot,'p_village_9',slot_town_housing_level,1),
			(party_set_slot,'p_village_9',slot_town_irrigation_level,1),
			(party_set_slot,'p_village_9',slot_town_mill_level,1),
			(party_set_slot,'p_village_9',slot_town_raided_by,null),
			(party_set_slot,'p_village_9',slot_town_state,sts_normal),
			(party_set_slot,'p_village_9',slot_town_raid_progress,null),
			(party_set_slot,'p_village_9',slot_town_recover_progress,null),
			(party_set_slot,'p_village_9',slot_town_production_bonus,1),
			(party_set_slot,'p_village_9',slot_town_siege_days,0),
			(party_set_slot,'p_village_9',slot_town_reserve_patrol,null),
			(party_set_slot,'p_village_9',slot_town_trade_good_productions_begin,null),
			(party_set_slot,'p_village_9',slot_town_trade_good_temp_productions_begin,null),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_village_9',slot_town_trade_good_price_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_village_9',slot_town_trade_good_abundance_array,'$return'),
			(party_set_slot,'p_village_9',slot_town_tax_rate,100),
			(party_set_slot,'p_village_9',slot_town_shoen,null),
			(party_set_slot,'p_village_9',slot_town_prefecture_array,null),
			(party_set_slot,'p_village_9',slot_town_reinforcements_a,'pt_village_reinforcements_a'),
			(party_set_slot,'p_village_9',slot_town_reinforcements_b,'pt_village_reinforcements_b'),
			(party_set_slot,'p_village_9',slot_town_reinforcements_c,'pt_village_reinforcements_c'),
			(party_set_slot,'p_village_9',slot_town_population,1000),
			(party_set_slot,'p_village_9',slot_town_population_max,5000),
			(party_set_slot,'p_village_9',slot_town_population_growth_factor,1),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_9',slot_town_demand_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_9',slot_town_storehouse_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_9',slot_town_facility_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_9',slot_town_surplus_array,'$return'),

			(party_set_slot,'p_village_10',slot_town_center,'scn_village'),
			(party_set_slot,'p_village_10',slot_town_castle,0),
			(party_set_slot,'p_village_10',slot_town_inn,0),
			(party_set_slot,'p_village_10',slot_town_store,0),
			(party_set_slot,'p_village_10',slot_town_smithy,0),
			(party_set_slot,'p_village_10',slot_town_capital,himeji),
			(party_set_slot,'p_village_10',slot_town_dojo,0),
			(party_set_slot,'p_village_10',slot_town_sensei,-1),
			(party_set_slot,'p_village_10',slot_town_kokujin,'trp_village_10_kokujin'),
			(party_set_slot,'p_village_10',slot_town_innkeeper,'trp_village_10_innkeeper'),
			(party_set_slot,'p_village_10',slot_town_merchant,'trp_village_10_merchant'),
			(party_set_slot,'p_village_10',slot_town_broker,null),
			(party_set_slot,'p_village_10',slot_town_moneychanger,null),
			(party_set_slot,'p_village_10',slot_town_fishmonger,'trp_village_10_fishmonger'),
			(party_set_slot,'p_village_10',slot_town_horse_trader,null),
			(party_set_slot,'p_village_10',slot_town_export_good,itm_kyoto_sake),
			(party_set_slot,'p_village_10',slot_town_export_rate,100),
			(party_set_slot,'p_village_10',slot_town_import_good,itm_salt),
			(party_set_slot,'p_village_10',slot_town_import_rate,100),
			(party_set_slot,'p_village_10',slot_town_terrain,ter_high_valley),
			(party_set_slot,'p_village_10',slot_town_size,ct_village),
			(party_set_slot,'p_village_10',slot_town_mercs,'p_village_10_mercs'),
			(party_set_slot,'p_village_10',slot_town_trade_hub,0),
			(call_script,'script_town_init_trade_dest','p_village_10',himeji,null,null,null,null,null),
			(party_set_slot,'p_village_10',slot_town_trade_month,7),
			(party_set_slot,'p_village_10',slot_town_att_to_player,att_cautious),
			(party_set_slot,'p_village_10',slot_town_player_relation,0),
			(party_set_slot,'p_village_10',slot_town_import_demand,3),
			(party_set_slot,'p_village_10',slot_town_export_demand,3),
			(party_set_slot,'p_village_10',slot_town_demand,0),
			(party_set_slot,'p_village_10',slot_town_treasury,3600),
			(party_set_slot,'p_village_10',slot_town_garrison_source,'p_village_garrison_source'),
			(party_set_slot,'p_village_10',slot_town_siege_active,0),
			(party_set_slot,'p_village_10',slot_town_under_siege,false),
			(party_set_slot,'p_village_10',slot_town_is_besieged_by,null),
			(party_set_slot,'p_village_10',slot_town_initial_faction,0),
			(party_set_slot,'p_village_10',slot_town_scene_flags,0),
			(party_set_slot,'p_village_10',slot_town_reserve_patrol,-1),
			(party_set_slot,'p_village_10',slot_town_spawn_points,1000),
			(party_set_slot,'p_village_10',slot_party_type,spt_city),
			(party_set_slot,'p_village_10',slot_party_food,5000),
			(party_set_slot,'p_village_10',slot_party_icon,'icon_village'),
			(party_set_slot,'p_village_10',slot_party_icon_state,tis_normal),
			(party_set_slot,'p_village_10',slot_party_ai_state,null),
			(party_set_slot,'p_village_10',slot_party_ai_object,null),
			(party_set_slot,'p_village_10',slot_town_accumulated_rents,0),
			(party_set_slot,'p_village_10',slot_town_accumulated_tariffs,0),
			(party_set_slot,'p_village_10',slot_town_current_improvement,null),
			(party_set_slot,'p_village_10',slot_town_improvement_end_hour,null),
			(party_set_slot,'p_village_10',slot_town_housing_level,1),
			(party_set_slot,'p_village_10',slot_town_irrigation_level,1),
			(party_set_slot,'p_village_10',slot_town_mill_level,1),
			(party_set_slot,'p_village_10',slot_town_raided_by,null),
			(party_set_slot,'p_village_10',slot_town_state,sts_normal),
			(party_set_slot,'p_village_10',slot_town_raid_progress,null),
			(party_set_slot,'p_village_10',slot_town_recover_progress,null),
			(party_set_slot,'p_village_10',slot_town_production_bonus,1),
			(party_set_slot,'p_village_10',slot_town_siege_days,0),
			(party_set_slot,'p_village_10',slot_town_reserve_patrol,null),
			(party_set_slot,'p_village_10',slot_town_trade_good_productions_begin,null),
			(party_set_slot,'p_village_10',slot_town_trade_good_temp_productions_begin,null),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_village_10',slot_town_trade_good_price_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_village_10',slot_town_trade_good_abundance_array,'$return'),
			(party_set_slot,'p_village_10',slot_town_tax_rate,100),
			(party_set_slot,'p_village_10',slot_town_shoen,null),
			(party_set_slot,'p_village_10',slot_town_prefecture_array,null),
			(party_set_slot,'p_village_10',slot_town_reinforcements_a,'pt_village_reinforcements_a'),
			(party_set_slot,'p_village_10',slot_town_reinforcements_b,'pt_village_reinforcements_b'),
			(party_set_slot,'p_village_10',slot_town_reinforcements_c,'pt_village_reinforcements_c'),
			(party_set_slot,'p_village_10',slot_town_population,1000),
			(party_set_slot,'p_village_10',slot_town_population_max,5000),
			(party_set_slot,'p_village_10',slot_town_population_growth_factor,1),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_10',slot_town_demand_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_10',slot_town_storehouse_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_10',slot_town_facility_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_10',slot_town_surplus_array,'$return'),

			(party_set_slot,'p_village_11',slot_town_center,'scn_village'),
			(party_set_slot,'p_village_11',slot_town_castle,0),
			(party_set_slot,'p_village_11',slot_town_inn,0),
			(party_set_slot,'p_village_11',slot_town_store,0),
			(party_set_slot,'p_village_11',slot_town_smithy,0),
			(party_set_slot,'p_village_11',slot_town_capital,kakogawa),
			(party_set_slot,'p_village_11',slot_town_dojo,0),
			(party_set_slot,'p_village_11',slot_town_sensei,-1),
			(party_set_slot,'p_village_11',slot_town_kokujin,'trp_village_11_kokujin'),
			(party_set_slot,'p_village_11',slot_town_innkeeper,'trp_village_11_innkeeper'),
			(party_set_slot,'p_village_11',slot_town_merchant,'trp_village_11_merchant'),
			(party_set_slot,'p_village_11',slot_town_broker,null),
			(party_set_slot,'p_village_11',slot_town_moneychanger,null),
			(party_set_slot,'p_village_11',slot_town_fishmonger,'trp_village_11_fishmonger'),
			(party_set_slot,'p_village_11',slot_town_horse_trader,null),
			(party_set_slot,'p_village_11',slot_town_export_good,itm_kyoto_sake),
			(party_set_slot,'p_village_11',slot_town_export_rate,100),
			(party_set_slot,'p_village_11',slot_town_import_good,itm_salt),
			(party_set_slot,'p_village_11',slot_town_import_rate,100),
			(party_set_slot,'p_village_11',slot_town_terrain,ter_lakeside),
			(party_set_slot,'p_village_11',slot_town_size,ct_village),
			(party_set_slot,'p_village_11',slot_town_mercs,'p_village_11_mercs'),
			(party_set_slot,'p_village_11',slot_town_trade_hub,0),
			(call_script,'script_town_init_trade_dest','p_village_11',sumoto,null,null,null,null,null),
			(party_set_slot,'p_village_11',slot_town_trade_month,10),
			(party_set_slot,'p_village_11',slot_town_att_to_player,att_cautious),
			(party_set_slot,'p_village_11',slot_town_player_relation,0),
			(party_set_slot,'p_village_11',slot_town_import_demand,3),
			(party_set_slot,'p_village_11',slot_town_export_demand,3),
			(party_set_slot,'p_village_11',slot_town_demand,0),
			(party_set_slot,'p_village_11',slot_town_treasury,3600),
			(party_set_slot,'p_village_11',slot_town_garrison_source,'p_village_garrison_source'),
			(party_set_slot,'p_village_11',slot_town_siege_active,0),
			(party_set_slot,'p_village_11',slot_town_under_siege,false),
			(party_set_slot,'p_village_11',slot_town_is_besieged_by,null),
			(party_set_slot,'p_village_11',slot_town_initial_faction,0),
			(party_set_slot,'p_village_11',slot_town_scene_flags,0),
			(party_set_slot,'p_village_11',slot_town_reserve_patrol,-1),
			(party_set_slot,'p_village_11',slot_town_spawn_points,1000),
			(party_set_slot,'p_village_11',slot_party_type,spt_city),
			(party_set_slot,'p_village_11',slot_party_food,5000),
			(party_set_slot,'p_village_11',slot_party_icon,'icon_village'),
			(party_set_slot,'p_village_11',slot_party_icon_state,tis_normal),
			(party_set_slot,'p_village_11',slot_party_ai_state,null),
			(party_set_slot,'p_village_11',slot_party_ai_object,null),
			(party_set_slot,'p_village_11',slot_town_accumulated_rents,0),
			(party_set_slot,'p_village_11',slot_town_accumulated_tariffs,0),
			(party_set_slot,'p_village_11',slot_town_current_improvement,null),
			(party_set_slot,'p_village_11',slot_town_improvement_end_hour,null),
			(party_set_slot,'p_village_11',slot_town_housing_level,1),
			(party_set_slot,'p_village_11',slot_town_irrigation_level,1),
			(party_set_slot,'p_village_11',slot_town_mill_level,1),
			(party_set_slot,'p_village_11',slot_town_raided_by,null),
			(party_set_slot,'p_village_11',slot_town_state,sts_normal),
			(party_set_slot,'p_village_11',slot_town_raid_progress,null),
			(party_set_slot,'p_village_11',slot_town_recover_progress,null),
			(party_set_slot,'p_village_11',slot_town_production_bonus,1),
			(party_set_slot,'p_village_11',slot_town_siege_days,0),
			(party_set_slot,'p_village_11',slot_town_reserve_patrol,null),
			(party_set_slot,'p_village_11',slot_town_trade_good_productions_begin,null),
			(party_set_slot,'p_village_11',slot_town_trade_good_temp_productions_begin,null),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_village_11',slot_town_trade_good_price_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_village_11',slot_town_trade_good_abundance_array,'$return'),
			(party_set_slot,'p_village_11',slot_town_tax_rate,100),
			(party_set_slot,'p_village_11',slot_town_shoen,null),
			(party_set_slot,'p_village_11',slot_town_prefecture_array,null),
			(party_set_slot,'p_village_11',slot_town_reinforcements_a,'pt_village_reinforcements_a'),
			(party_set_slot,'p_village_11',slot_town_reinforcements_b,'pt_village_reinforcements_b'),
			(party_set_slot,'p_village_11',slot_town_reinforcements_c,'pt_village_reinforcements_c'),
			(party_set_slot,'p_village_11',slot_town_population,1000),
			(party_set_slot,'p_village_11',slot_town_population_max,5000),
			(party_set_slot,'p_village_11',slot_town_population_growth_factor,1),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_11',slot_town_demand_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_11',slot_town_storehouse_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_11',slot_town_facility_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_11',slot_town_surplus_array,'$return'),

			(party_set_slot,'p_village_12',slot_town_center,'scn_village'),
			(party_set_slot,'p_village_12',slot_town_castle,0),
			(party_set_slot,'p_village_12',slot_town_inn,0),
			(party_set_slot,'p_village_12',slot_town_store,0),
			(party_set_slot,'p_village_12',slot_town_smithy,0),
			(party_set_slot,'p_village_12',slot_town_capital,tsuruga),
			(party_set_slot,'p_village_12',slot_town_dojo,'scn_imazu_dojo'),
			(party_set_slot,'p_village_12',slot_town_sensei,'trp_ietsuru'),
			(party_set_slot,'p_village_12',slot_town_kokujin,'trp_village_12_kokujin'),
			(party_set_slot,'p_village_12',slot_town_innkeeper,'trp_village_12_innkeeper'),
			(party_set_slot,'p_village_12',slot_town_merchant,'trp_village_12_merchant'),
			(party_set_slot,'p_village_12',slot_town_broker,null),
			(party_set_slot,'p_village_12',slot_town_moneychanger,null),
			(party_set_slot,'p_village_12',slot_town_fishmonger,'trp_village_12_fishmonger'),
			(party_set_slot,'p_village_12',slot_town_horse_trader,null),
			(party_set_slot,'p_village_12',slot_town_export_good,itm_kyoto_sake),
			(party_set_slot,'p_village_12',slot_town_export_rate,100),
			(party_set_slot,'p_village_12',slot_town_import_good,itm_salt),
			(party_set_slot,'p_village_12',slot_town_import_rate,100),
			(party_set_slot,'p_village_12',slot_town_terrain,ter_island),
			(party_set_slot,'p_village_12',slot_town_size,ct_village),
			(party_set_slot,'p_village_12',slot_town_mercs,'p_village_12_mercs'),
			(party_set_slot,'p_village_12',slot_town_trade_hub,0),
			(call_script,'script_town_init_trade_dest','p_village_12',takashima,null,null,null,null,null),
			(party_set_slot,'p_village_12',slot_town_trade_month,4),
			(party_set_slot,'p_village_12',slot_town_att_to_player,att_cautious),
			(party_set_slot,'p_village_12',slot_town_player_relation,0),
			(party_set_slot,'p_village_12',slot_town_import_demand,3),
			(party_set_slot,'p_village_12',slot_town_export_demand,3),
			(party_set_slot,'p_village_12',slot_town_demand,0),
			(party_set_slot,'p_village_12',slot_town_treasury,3600),
			(party_set_slot,'p_village_12',slot_town_garrison_source,'p_village_garrison_source'),
			(party_set_slot,'p_village_12',slot_town_siege_active,0),
			(party_set_slot,'p_village_12',slot_town_under_siege,false),
			(party_set_slot,'p_village_12',slot_town_is_besieged_by,null),
			(party_set_slot,'p_village_12',slot_town_initial_faction,0),
			(party_set_slot,'p_village_12',slot_town_scene_flags,0),
			(party_set_slot,'p_village_12',slot_town_reserve_patrol,-1),
			(party_set_slot,'p_village_12',slot_town_spawn_points,1000),
			(party_set_slot,'p_village_12',slot_party_type,spt_city),
			(party_set_slot,'p_village_12',slot_party_food,5000),
			(party_set_slot,'p_village_12',slot_party_icon,'icon_village'),
			(party_set_slot,'p_village_12',slot_party_icon_state,tis_normal),
			(party_set_slot,'p_village_12',slot_party_ai_state,null),
			(party_set_slot,'p_village_12',slot_party_ai_object,null),
			(party_set_slot,'p_village_12',slot_town_accumulated_rents,0),
			(party_set_slot,'p_village_12',slot_town_accumulated_tariffs,0),
			(party_set_slot,'p_village_12',slot_town_current_improvement,null),
			(party_set_slot,'p_village_12',slot_town_improvement_end_hour,null),
			(party_set_slot,'p_village_12',slot_town_housing_level,1),
			(party_set_slot,'p_village_12',slot_town_irrigation_level,1),
			(party_set_slot,'p_village_12',slot_town_mill_level,1),
			(party_set_slot,'p_village_12',slot_town_raided_by,null),
			(party_set_slot,'p_village_12',slot_town_state,sts_normal),
			(party_set_slot,'p_village_12',slot_town_raid_progress,null),
			(party_set_slot,'p_village_12',slot_town_recover_progress,null),
			(party_set_slot,'p_village_12',slot_town_production_bonus,1),
			(party_set_slot,'p_village_12',slot_town_siege_days,0),
			(party_set_slot,'p_village_12',slot_town_reserve_patrol,null),
			(party_set_slot,'p_village_12',slot_town_trade_good_productions_begin,null),
			(party_set_slot,'p_village_12',slot_town_trade_good_temp_productions_begin,null),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_village_12',slot_town_trade_good_price_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_village_12',slot_town_trade_good_abundance_array,'$return'),
			(party_set_slot,'p_village_12',slot_town_tax_rate,100),
			(party_set_slot,'p_village_12',slot_town_shoen,null),
			(party_set_slot,'p_village_12',slot_town_prefecture_array,null),
			(party_set_slot,'p_village_12',slot_town_reinforcements_a,'pt_village_reinforcements_a'),
			(party_set_slot,'p_village_12',slot_town_reinforcements_b,'pt_village_reinforcements_b'),
			(party_set_slot,'p_village_12',slot_town_reinforcements_c,'pt_village_reinforcements_c'),
			(party_set_slot,'p_village_12',slot_town_population,1000),
			(party_set_slot,'p_village_12',slot_town_population_max,5000),
			(party_set_slot,'p_village_12',slot_town_population_growth_factor,1),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_12',slot_town_demand_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_12',slot_town_storehouse_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_12',slot_town_facility_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_12',slot_town_surplus_array,'$return'),

			(party_set_slot,'p_village_13',slot_town_center,'scn_village'),
			(party_set_slot,'p_village_13',slot_town_castle,0),
			(party_set_slot,'p_village_13',slot_town_inn,0),
			(party_set_slot,'p_village_13',slot_town_store,0),
			(party_set_slot,'p_village_13',slot_town_smithy,0),
			(party_set_slot,'p_village_13',slot_town_capital,kameyama),
			(party_set_slot,'p_village_13',slot_town_dojo,0),
			(party_set_slot,'p_village_13',slot_town_sensei,-1),
			(party_set_slot,'p_village_13',slot_town_kokujin,'trp_village_13_kokujin'),
			(party_set_slot,'p_village_13',slot_town_innkeeper,'trp_village_13_innkeeper'),
			(party_set_slot,'p_village_13',slot_town_merchant,'trp_village_13_merchant'),
			(party_set_slot,'p_village_13',slot_town_broker,null),
			(party_set_slot,'p_village_13',slot_town_moneychanger,null),
			(party_set_slot,'p_village_13',slot_town_fishmonger,'trp_village_13_fishmonger'),
			(party_set_slot,'p_village_13',slot_town_horse_trader,null),
			(party_set_slot,'p_village_13',slot_town_export_good,itm_kyoto_sake),
			(party_set_slot,'p_village_13',slot_town_export_rate,100),
			(party_set_slot,'p_village_13',slot_town_import_good,itm_salt),
			(party_set_slot,'p_village_13',slot_town_import_rate,100),
			(party_set_slot,'p_village_13',slot_town_terrain,ter_high_valley),
			(party_set_slot,'p_village_13',slot_town_size,ct_small_village),
			(party_set_slot,'p_village_13',slot_town_mercs,'p_village_13_mercs'),
			(party_set_slot,'p_village_13',slot_town_trade_hub,0),
			(call_script,'script_town_init_trade_dest','p_village_13',kameyama,null,null,null,null,null),
			(party_set_slot,'p_village_13',slot_town_trade_month,7),
			(party_set_slot,'p_village_13',slot_town_att_to_player,att_cautious),
			(party_set_slot,'p_village_13',slot_town_player_relation,0),
			(party_set_slot,'p_village_13',slot_town_import_demand,3),
			(party_set_slot,'p_village_13',slot_town_export_demand,3),
			(party_set_slot,'p_village_13',slot_town_demand,0),
			(party_set_slot,'p_village_13',slot_town_treasury,3600),
			(party_set_slot,'p_village_13',slot_town_garrison_source,'p_village_garrison_source'),
			(party_set_slot,'p_village_13',slot_town_siege_active,0),
			(party_set_slot,'p_village_13',slot_town_under_siege,false),
			(party_set_slot,'p_village_13',slot_town_is_besieged_by,null),
			(party_set_slot,'p_village_13',slot_town_initial_faction,0),
			(party_set_slot,'p_village_13',slot_town_scene_flags,0),
			(party_set_slot,'p_village_13',slot_town_reserve_patrol,-1),
			(party_set_slot,'p_village_13',slot_town_spawn_points,1000),
			(party_set_slot,'p_village_13',slot_party_type,spt_city),
			(party_set_slot,'p_village_13',slot_party_food,5000),
			(party_set_slot,'p_village_13',slot_party_icon,'icon_village'),
			(party_set_slot,'p_village_13',slot_party_icon_state,tis_normal),
			(party_set_slot,'p_village_13',slot_party_ai_state,null),
			(party_set_slot,'p_village_13',slot_party_ai_object,null),
			(party_set_slot,'p_village_13',slot_town_accumulated_rents,0),
			(party_set_slot,'p_village_13',slot_town_accumulated_tariffs,0),
			(party_set_slot,'p_village_13',slot_town_current_improvement,null),
			(party_set_slot,'p_village_13',slot_town_improvement_end_hour,null),
			(party_set_slot,'p_village_13',slot_town_housing_level,1),
			(party_set_slot,'p_village_13',slot_town_irrigation_level,1),
			(party_set_slot,'p_village_13',slot_town_mill_level,1),
			(party_set_slot,'p_village_13',slot_town_raided_by,null),
			(party_set_slot,'p_village_13',slot_town_state,sts_normal),
			(party_set_slot,'p_village_13',slot_town_raid_progress,null),
			(party_set_slot,'p_village_13',slot_town_recover_progress,null),
			(party_set_slot,'p_village_13',slot_town_production_bonus,1),
			(party_set_slot,'p_village_13',slot_town_siege_days,0),
			(party_set_slot,'p_village_13',slot_town_reserve_patrol,null),
			(party_set_slot,'p_village_13',slot_town_trade_good_productions_begin,null),
			(party_set_slot,'p_village_13',slot_town_trade_good_temp_productions_begin,null),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_village_13',slot_town_trade_good_price_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_village_13',slot_town_trade_good_abundance_array,'$return'),
			(party_set_slot,'p_village_13',slot_town_tax_rate,100),
			(party_set_slot,'p_village_13',slot_town_shoen,null),
			(party_set_slot,'p_village_13',slot_town_prefecture_array,null),
			(party_set_slot,'p_village_13',slot_town_reinforcements_a,'pt_village_reinforcements_a'),
			(party_set_slot,'p_village_13',slot_town_reinforcements_b,'pt_village_reinforcements_b'),
			(party_set_slot,'p_village_13',slot_town_reinforcements_c,'pt_village_reinforcements_c'),
			(party_set_slot,'p_village_13',slot_town_population,1000),
			(party_set_slot,'p_village_13',slot_town_population_max,5000),
			(party_set_slot,'p_village_13',slot_town_population_growth_factor,1),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_13',slot_town_demand_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_13',slot_town_storehouse_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_13',slot_town_facility_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_13',slot_town_surplus_array,'$return'),

			(party_set_slot,'p_village_14',slot_town_center,'scn_village'),
			(party_set_slot,'p_village_14',slot_town_castle,0),
			(party_set_slot,'p_village_14',slot_town_inn,0),
			(party_set_slot,'p_village_14',slot_town_store,0),
			(party_set_slot,'p_village_14',slot_town_smithy,0),
			(party_set_slot,'p_village_14',slot_town_capital,obama),
			(party_set_slot,'p_village_14',slot_town_dojo,0),
			(party_set_slot,'p_village_14',slot_town_sensei,-1),
			(party_set_slot,'p_village_14',slot_town_kokujin,'trp_village_14_kokujin'),
			(party_set_slot,'p_village_14',slot_town_innkeeper,'trp_village_14_innkeeper'),
			(party_set_slot,'p_village_14',slot_town_merchant,'trp_village_14_merchant'),
			(party_set_slot,'p_village_14',slot_town_broker,null),
			(party_set_slot,'p_village_14',slot_town_moneychanger,null),
			(party_set_slot,'p_village_14',slot_town_fishmonger,'trp_village_14_fishmonger'),
			(party_set_slot,'p_village_14',slot_town_horse_trader,null),
			(party_set_slot,'p_village_14',slot_town_export_good,itm_kyoto_sake),
			(party_set_slot,'p_village_14',slot_town_export_rate,100),
			(party_set_slot,'p_village_14',slot_town_import_good,itm_salt),
			(party_set_slot,'p_village_14',slot_town_import_rate,100),
			(party_set_slot,'p_village_14',slot_town_terrain,ter_seaside),
			(party_set_slot,'p_village_14',slot_town_size,ct_small_village),
			(party_set_slot,'p_village_14',slot_town_mercs,'p_village_14_mercs'),
			(party_set_slot,'p_village_14',slot_town_trade_hub,0),
			(call_script,'script_town_init_trade_dest','p_village_14',tsuruga,null,null,null,null,null),
			(party_set_slot,'p_village_14',slot_town_trade_month,10),
			(party_set_slot,'p_village_14',slot_town_att_to_player,att_cautious),
			(party_set_slot,'p_village_14',slot_town_player_relation,0),
			(party_set_slot,'p_village_14',slot_town_import_demand,3),
			(party_set_slot,'p_village_14',slot_town_export_demand,3),
			(party_set_slot,'p_village_14',slot_town_demand,0),
			(party_set_slot,'p_village_14',slot_town_treasury,3600),
			(party_set_slot,'p_village_14',slot_town_garrison_source,'p_village_garrison_source'),
			(party_set_slot,'p_village_14',slot_town_siege_active,0),
			(party_set_slot,'p_village_14',slot_town_under_siege,false),
			(party_set_slot,'p_village_14',slot_town_is_besieged_by,null),
			(party_set_slot,'p_village_14',slot_town_initial_faction,0),
			(party_set_slot,'p_village_14',slot_town_scene_flags,0),
			(party_set_slot,'p_village_14',slot_town_reserve_patrol,-1),
			(party_set_slot,'p_village_14',slot_town_spawn_points,1000),
			(party_set_slot,'p_village_14',slot_party_type,spt_city),
			(party_set_slot,'p_village_14',slot_party_food,5000),
			(party_set_slot,'p_village_14',slot_party_icon,'icon_village'),
			(party_set_slot,'p_village_14',slot_party_icon_state,tis_normal),
			(party_set_slot,'p_village_14',slot_party_ai_state,null),
			(party_set_slot,'p_village_14',slot_party_ai_object,null),
			(party_set_slot,'p_village_14',slot_town_accumulated_rents,0),
			(party_set_slot,'p_village_14',slot_town_accumulated_tariffs,0),
			(party_set_slot,'p_village_14',slot_town_current_improvement,null),
			(party_set_slot,'p_village_14',slot_town_improvement_end_hour,null),
			(party_set_slot,'p_village_14',slot_town_housing_level,1),
			(party_set_slot,'p_village_14',slot_town_irrigation_level,1),
			(party_set_slot,'p_village_14',slot_town_mill_level,1),
			(party_set_slot,'p_village_14',slot_town_raided_by,null),
			(party_set_slot,'p_village_14',slot_town_state,sts_normal),
			(party_set_slot,'p_village_14',slot_town_raid_progress,null),
			(party_set_slot,'p_village_14',slot_town_recover_progress,null),
			(party_set_slot,'p_village_14',slot_town_production_bonus,1),
			(party_set_slot,'p_village_14',slot_town_siege_days,0),
			(party_set_slot,'p_village_14',slot_town_reserve_patrol,null),
			(party_set_slot,'p_village_14',slot_town_trade_good_productions_begin,null),
			(party_set_slot,'p_village_14',slot_town_trade_good_temp_productions_begin,null),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_village_14',slot_town_trade_good_price_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_village_14',slot_town_trade_good_abundance_array,'$return'),
			(party_set_slot,'p_village_14',slot_town_tax_rate,100),
			(party_set_slot,'p_village_14',slot_town_shoen,null),
			(party_set_slot,'p_village_14',slot_town_prefecture_array,null),
			(party_set_slot,'p_village_14',slot_town_reinforcements_a,'pt_village_reinforcements_a'),
			(party_set_slot,'p_village_14',slot_town_reinforcements_b,'pt_village_reinforcements_b'),
			(party_set_slot,'p_village_14',slot_town_reinforcements_c,'pt_village_reinforcements_c'),
			(party_set_slot,'p_village_14',slot_town_population,1000),
			(party_set_slot,'p_village_14',slot_town_population_max,5000),
			(party_set_slot,'p_village_14',slot_town_population_growth_factor,1),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_14',slot_town_demand_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_14',slot_town_storehouse_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_14',slot_town_facility_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_14',slot_town_surplus_array,'$return'),

			(party_set_slot,'p_village_15',slot_town_center,'scn_village'),
			(party_set_slot,'p_village_15',slot_town_castle,0),
			(party_set_slot,'p_village_15',slot_town_inn,0),
			(party_set_slot,'p_village_15',slot_town_store,0),
			(party_set_slot,'p_village_15',slot_town_smithy,0),
			(party_set_slot,'p_village_15',slot_town_capital,kameyama),
			(party_set_slot,'p_village_15',slot_town_dojo,0),
			(party_set_slot,'p_village_15',slot_town_sensei,-1),
			(party_set_slot,'p_village_15',slot_town_kokujin,'trp_village_15_kokujin'),
			(party_set_slot,'p_village_15',slot_town_innkeeper,'trp_village_15_innkeeper'),
			(party_set_slot,'p_village_15',slot_town_merchant,'trp_village_15_merchant'),
			(party_set_slot,'p_village_15',slot_town_broker,null),
			(party_set_slot,'p_village_15',slot_town_moneychanger,null),
			(party_set_slot,'p_village_15',slot_town_fishmonger,'trp_village_15_fishmonger'),
			(party_set_slot,'p_village_15',slot_town_horse_trader,null),
			(party_set_slot,'p_village_15',slot_town_export_good,itm_kyoto_sake),
			(party_set_slot,'p_village_15',slot_town_export_rate,100),
			(party_set_slot,'p_village_15',slot_town_import_good,itm_salt),
			(party_set_slot,'p_village_15',slot_town_import_rate,100),
			(party_set_slot,'p_village_15',slot_town_terrain,ter_high_valley),
			(party_set_slot,'p_village_15',slot_town_size,ct_small_village),
			(party_set_slot,'p_village_15',slot_town_mercs,'p_village_15_mercs'),
			(party_set_slot,'p_village_15',slot_town_trade_hub,0),
			(call_script,'script_town_init_trade_dest','p_village_15',kameyama,null,null,null,null,null),
			(party_set_slot,'p_village_15',slot_town_trade_month,4),
			(party_set_slot,'p_village_15',slot_town_att_to_player,att_cautious),
			(party_set_slot,'p_village_15',slot_town_player_relation,0),
			(party_set_slot,'p_village_15',slot_town_import_demand,3),
			(party_set_slot,'p_village_15',slot_town_export_demand,3),
			(party_set_slot,'p_village_15',slot_town_demand,0),
			(party_set_slot,'p_village_15',slot_town_treasury,3600),
			(party_set_slot,'p_village_15',slot_town_garrison_source,'p_village_garrison_source'),
			(party_set_slot,'p_village_15',slot_town_siege_active,0),
			(party_set_slot,'p_village_15',slot_town_under_siege,false),
			(party_set_slot,'p_village_15',slot_town_is_besieged_by,null),
			(party_set_slot,'p_village_15',slot_town_initial_faction,0),
			(party_set_slot,'p_village_15',slot_town_scene_flags,0),
			(party_set_slot,'p_village_15',slot_town_reserve_patrol,-1),
			(party_set_slot,'p_village_15',slot_town_spawn_points,1000),
			(party_set_slot,'p_village_15',slot_party_type,spt_city),
			(party_set_slot,'p_village_15',slot_party_food,5000),
			(party_set_slot,'p_village_15',slot_party_icon,'icon_village'),
			(party_set_slot,'p_village_15',slot_party_icon_state,tis_normal),
			(party_set_slot,'p_village_15',slot_party_ai_state,null),
			(party_set_slot,'p_village_15',slot_party_ai_object,null),
			(party_set_slot,'p_village_15',slot_town_accumulated_rents,0),
			(party_set_slot,'p_village_15',slot_town_accumulated_tariffs,0),
			(party_set_slot,'p_village_15',slot_town_current_improvement,null),
			(party_set_slot,'p_village_15',slot_town_improvement_end_hour,null),
			(party_set_slot,'p_village_15',slot_town_housing_level,1),
			(party_set_slot,'p_village_15',slot_town_irrigation_level,1),
			(party_set_slot,'p_village_15',slot_town_mill_level,1),
			(party_set_slot,'p_village_15',slot_town_raided_by,null),
			(party_set_slot,'p_village_15',slot_town_state,sts_normal),
			(party_set_slot,'p_village_15',slot_town_raid_progress,null),
			(party_set_slot,'p_village_15',slot_town_recover_progress,null),
			(party_set_slot,'p_village_15',slot_town_production_bonus,1),
			(party_set_slot,'p_village_15',slot_town_siege_days,0),
			(party_set_slot,'p_village_15',slot_town_reserve_patrol,null),
			(party_set_slot,'p_village_15',slot_town_trade_good_productions_begin,null),
			(party_set_slot,'p_village_15',slot_town_trade_good_temp_productions_begin,null),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_village_15',slot_town_trade_good_price_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_village_15',slot_town_trade_good_abundance_array,'$return'),
			(party_set_slot,'p_village_15',slot_town_tax_rate,100),
			(party_set_slot,'p_village_15',slot_town_shoen,null),
			(party_set_slot,'p_village_15',slot_town_prefecture_array,null),
			(party_set_slot,'p_village_15',slot_town_reinforcements_a,'pt_village_reinforcements_a'),
			(party_set_slot,'p_village_15',slot_town_reinforcements_b,'pt_village_reinforcements_b'),
			(party_set_slot,'p_village_15',slot_town_reinforcements_c,'pt_village_reinforcements_c'),
			(party_set_slot,'p_village_15',slot_town_population,1000),
			(party_set_slot,'p_village_15',slot_town_population_max,5000),
			(party_set_slot,'p_village_15',slot_town_population_growth_factor,1),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_15',slot_town_demand_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_15',slot_town_storehouse_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_15',slot_town_facility_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_15',slot_town_surplus_array,'$return'),

			(party_set_slot,'p_village_16',slot_town_center,'scn_village'),
			(party_set_slot,'p_village_16',slot_town_castle,0),
			(party_set_slot,'p_village_16',slot_town_inn,0),
			(party_set_slot,'p_village_16',slot_town_store,0),
			(party_set_slot,'p_village_16',slot_town_smithy,0),
			(party_set_slot,'p_village_16',slot_town_capital,wakayama),
			(party_set_slot,'p_village_16',slot_town_dojo,0),
			(party_set_slot,'p_village_16',slot_town_sensei,-1),
			(party_set_slot,'p_village_16',slot_town_kokujin,'trp_village_16_kokujin'),
			(party_set_slot,'p_village_16',slot_town_innkeeper,'trp_village_16_innkeeper'),
			(party_set_slot,'p_village_16',slot_town_merchant,'trp_village_16_merchant'),
			(party_set_slot,'p_village_16',slot_town_broker,null),
			(party_set_slot,'p_village_16',slot_town_moneychanger,null),
			(party_set_slot,'p_village_16',slot_town_fishmonger,'trp_village_16_fishmonger'),
			(party_set_slot,'p_village_16',slot_town_horse_trader,null),
			(party_set_slot,'p_village_16',slot_town_export_good,itm_kyoto_sake),
			(party_set_slot,'p_village_16',slot_town_export_rate,100),
			(party_set_slot,'p_village_16',slot_town_import_good,itm_salt),
			(party_set_slot,'p_village_16',slot_town_import_rate,100),
			(party_set_slot,'p_village_16',slot_town_terrain,ter_low_valley),
			(party_set_slot,'p_village_16',slot_town_size,ct_village),
			(party_set_slot,'p_village_16',slot_town_mercs,'p_village_16_mercs'),
			(party_set_slot,'p_village_16',slot_town_trade_hub,0),
			(call_script,'script_town_init_trade_dest','p_village_16',wakayama,null,null,null,null,null),
			(party_set_slot,'p_village_16',slot_town_trade_month,7),
			(party_set_slot,'p_village_16',slot_town_att_to_player,att_cautious),
			(party_set_slot,'p_village_16',slot_town_player_relation,0),
			(party_set_slot,'p_village_16',slot_town_import_demand,3),
			(party_set_slot,'p_village_16',slot_town_export_demand,3),
			(party_set_slot,'p_village_16',slot_town_demand,0),
			(party_set_slot,'p_village_16',slot_town_treasury,3600),
			(party_set_slot,'p_village_16',slot_town_garrison_source,'p_village_garrison_source'),
			(party_set_slot,'p_village_16',slot_town_siege_active,0),
			(party_set_slot,'p_village_16',slot_town_under_siege,false),
			(party_set_slot,'p_village_16',slot_town_is_besieged_by,null),
			(party_set_slot,'p_village_16',slot_town_initial_faction,0),
			(party_set_slot,'p_village_16',slot_town_scene_flags,0),
			(party_set_slot,'p_village_16',slot_town_reserve_patrol,-1),
			(party_set_slot,'p_village_16',slot_town_spawn_points,1000),
			(party_set_slot,'p_village_16',slot_party_type,spt_city),
			(party_set_slot,'p_village_16',slot_party_food,5000),
			(party_set_slot,'p_village_16',slot_party_icon,'icon_village'),
			(party_set_slot,'p_village_16',slot_party_icon_state,tis_normal),
			(party_set_slot,'p_village_16',slot_party_ai_state,null),
			(party_set_slot,'p_village_16',slot_party_ai_object,null),
			(party_set_slot,'p_village_16',slot_town_accumulated_rents,0),
			(party_set_slot,'p_village_16',slot_town_accumulated_tariffs,0),
			(party_set_slot,'p_village_16',slot_town_current_improvement,null),
			(party_set_slot,'p_village_16',slot_town_improvement_end_hour,null),
			(party_set_slot,'p_village_16',slot_town_housing_level,1),
			(party_set_slot,'p_village_16',slot_town_irrigation_level,1),
			(party_set_slot,'p_village_16',slot_town_mill_level,1),
			(party_set_slot,'p_village_16',slot_town_raided_by,null),
			(party_set_slot,'p_village_16',slot_town_state,sts_normal),
			(party_set_slot,'p_village_16',slot_town_raid_progress,null),
			(party_set_slot,'p_village_16',slot_town_recover_progress,null),
			(party_set_slot,'p_village_16',slot_town_production_bonus,1),
			(party_set_slot,'p_village_16',slot_town_siege_days,0),
			(party_set_slot,'p_village_16',slot_town_reserve_patrol,null),
			(party_set_slot,'p_village_16',slot_town_trade_good_productions_begin,null),
			(party_set_slot,'p_village_16',slot_town_trade_good_temp_productions_begin,null),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_village_16',slot_town_trade_good_price_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_village_16',slot_town_trade_good_abundance_array,'$return'),
			(party_set_slot,'p_village_16',slot_town_tax_rate,100),
			(party_set_slot,'p_village_16',slot_town_shoen,null),
			(party_set_slot,'p_village_16',slot_town_prefecture_array,null),
			(party_set_slot,'p_village_16',slot_town_reinforcements_a,'pt_village_reinforcements_a'),
			(party_set_slot,'p_village_16',slot_town_reinforcements_b,'pt_village_reinforcements_b'),
			(party_set_slot,'p_village_16',slot_town_reinforcements_c,'pt_village_reinforcements_c'),
			(party_set_slot,'p_village_16',slot_town_population,1000),
			(party_set_slot,'p_village_16',slot_town_population_max,5000),
			(party_set_slot,'p_village_16',slot_town_population_growth_factor,1),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_16',slot_town_demand_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_16',slot_town_storehouse_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_16',slot_town_facility_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_16',slot_town_surplus_array,'$return'),

			(party_set_slot,'p_village_17',slot_town_center,'scn_village'),
			(party_set_slot,'p_village_17',slot_town_castle,0),
			(party_set_slot,'p_village_17',slot_town_inn,0),
			(party_set_slot,'p_village_17',slot_town_store,0),
			(party_set_slot,'p_village_17',slot_town_smithy,0),
			(party_set_slot,'p_village_17',slot_town_capital,fukuchiyama),
			(party_set_slot,'p_village_17',slot_town_dojo,0),
			(party_set_slot,'p_village_17',slot_town_sensei,-1),
			(party_set_slot,'p_village_17',slot_town_kokujin,'trp_village_17_kokujin'),
			(party_set_slot,'p_village_17',slot_town_innkeeper,'trp_village_17_innkeeper'),
			(party_set_slot,'p_village_17',slot_town_merchant,'trp_village_17_merchant'),
			(party_set_slot,'p_village_17',slot_town_broker,null),
			(party_set_slot,'p_village_17',slot_town_moneychanger,null),
			(party_set_slot,'p_village_17',slot_town_fishmonger,'trp_village_17_fishmonger'),
			(party_set_slot,'p_village_17',slot_town_horse_trader,null),
			(party_set_slot,'p_village_17',slot_town_export_good,itm_kyoto_sake),
			(party_set_slot,'p_village_17',slot_town_export_rate,100),
			(party_set_slot,'p_village_17',slot_town_import_good,itm_salt),
			(party_set_slot,'p_village_17',slot_town_import_rate,100),
			(party_set_slot,'p_village_17',slot_town_terrain,ter_low_valley),
			(party_set_slot,'p_village_17',slot_town_size,ct_village),
			(party_set_slot,'p_village_17',slot_town_mercs,'p_village_17_mercs'),
			(party_set_slot,'p_village_17',slot_town_trade_hub,0),
			(call_script,'script_town_init_trade_dest','p_village_17',hidaka,null,null,null,null,null),
			(party_set_slot,'p_village_17',slot_town_trade_month,10),
			(party_set_slot,'p_village_17',slot_town_att_to_player,att_cautious),
			(party_set_slot,'p_village_17',slot_town_player_relation,0),
			(party_set_slot,'p_village_17',slot_town_import_demand,3),
			(party_set_slot,'p_village_17',slot_town_export_demand,3),
			(party_set_slot,'p_village_17',slot_town_demand,0),
			(party_set_slot,'p_village_17',slot_town_treasury,3600),
			(party_set_slot,'p_village_17',slot_town_garrison_source,'p_village_garrison_source'),
			(party_set_slot,'p_village_17',slot_town_siege_active,0),
			(party_set_slot,'p_village_17',slot_town_under_siege,false),
			(party_set_slot,'p_village_17',slot_town_is_besieged_by,null),
			(party_set_slot,'p_village_17',slot_town_initial_faction,0),
			(party_set_slot,'p_village_17',slot_town_scene_flags,0),
			(party_set_slot,'p_village_17',slot_town_reserve_patrol,-1),
			(party_set_slot,'p_village_17',slot_town_spawn_points,1000),
			(party_set_slot,'p_village_17',slot_party_type,spt_city),
			(party_set_slot,'p_village_17',slot_party_food,5000),
			(party_set_slot,'p_village_17',slot_party_icon,'icon_village'),
			(party_set_slot,'p_village_17',slot_party_icon_state,tis_normal),
			(party_set_slot,'p_village_17',slot_party_ai_state,null),
			(party_set_slot,'p_village_17',slot_party_ai_object,null),
			(party_set_slot,'p_village_17',slot_town_accumulated_rents,0),
			(party_set_slot,'p_village_17',slot_town_accumulated_tariffs,0),
			(party_set_slot,'p_village_17',slot_town_current_improvement,null),
			(party_set_slot,'p_village_17',slot_town_improvement_end_hour,null),
			(party_set_slot,'p_village_17',slot_town_housing_level,1),
			(party_set_slot,'p_village_17',slot_town_irrigation_level,1),
			(party_set_slot,'p_village_17',slot_town_mill_level,1),
			(party_set_slot,'p_village_17',slot_town_raided_by,null),
			(party_set_slot,'p_village_17',slot_town_state,sts_normal),
			(party_set_slot,'p_village_17',slot_town_raid_progress,null),
			(party_set_slot,'p_village_17',slot_town_recover_progress,null),
			(party_set_slot,'p_village_17',slot_town_production_bonus,1),
			(party_set_slot,'p_village_17',slot_town_siege_days,0),
			(party_set_slot,'p_village_17',slot_town_reserve_patrol,null),
			(party_set_slot,'p_village_17',slot_town_trade_good_productions_begin,null),
			(party_set_slot,'p_village_17',slot_town_trade_good_temp_productions_begin,null),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_village_17',slot_town_trade_good_price_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_village_17',slot_town_trade_good_abundance_array,'$return'),
			(party_set_slot,'p_village_17',slot_town_tax_rate,100),
			(party_set_slot,'p_village_17',slot_town_shoen,null),
			(party_set_slot,'p_village_17',slot_town_prefecture_array,null),
			(party_set_slot,'p_village_17',slot_town_reinforcements_a,'pt_village_reinforcements_a'),
			(party_set_slot,'p_village_17',slot_town_reinforcements_b,'pt_village_reinforcements_b'),
			(party_set_slot,'p_village_17',slot_town_reinforcements_c,'pt_village_reinforcements_c'),
			(party_set_slot,'p_village_17',slot_town_population,1000),
			(party_set_slot,'p_village_17',slot_town_population_max,5000),
			(party_set_slot,'p_village_17',slot_town_population_growth_factor,1),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_17',slot_town_demand_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_17',slot_town_storehouse_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_17',slot_town_facility_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_17',slot_town_surplus_array,'$return'),

			(party_set_slot,'p_village_18',slot_town_center,'scn_village'),
			(party_set_slot,'p_village_18',slot_town_castle,0),
			(party_set_slot,'p_village_18',slot_town_inn,0),
			(party_set_slot,'p_village_18',slot_town_store,0),
			(party_set_slot,'p_village_18',slot_town_smithy,0),
			(party_set_slot,'p_village_18',slot_town_capital,hidaka),
			(party_set_slot,'p_village_18',slot_town_dojo,0),
			(party_set_slot,'p_village_18',slot_town_sensei,-1),
			(party_set_slot,'p_village_18',slot_town_kokujin,'trp_village_18_kokujin'),
			(party_set_slot,'p_village_18',slot_town_innkeeper,'trp_village_18_innkeeper'),
			(party_set_slot,'p_village_18',slot_town_merchant,'trp_village_18_merchant'),
			(party_set_slot,'p_village_18',slot_town_broker,null),
			(party_set_slot,'p_village_18',slot_town_moneychanger,null),
			(party_set_slot,'p_village_18',slot_town_fishmonger,'trp_village_18_fishmonger'),
			(party_set_slot,'p_village_18',slot_town_horse_trader,null),
			(party_set_slot,'p_village_18',slot_town_export_good,itm_kyoto_sake),
			(party_set_slot,'p_village_18',slot_town_export_rate,100),
			(party_set_slot,'p_village_18',slot_town_import_good,itm_salt),
			(party_set_slot,'p_village_18',slot_town_import_rate,100),
			(party_set_slot,'p_village_18',slot_town_terrain,ter_seaside),
			(party_set_slot,'p_village_18',slot_town_size,ct_village),
			(party_set_slot,'p_village_18',slot_town_mercs,'p_village_18_mercs'),
			(party_set_slot,'p_village_18',slot_town_trade_hub,0),
			(call_script,'script_town_init_trade_dest','p_village_18',kasumi,null,null,null,null,null),
			(party_set_slot,'p_village_18',slot_town_trade_month,4),
			(party_set_slot,'p_village_18',slot_town_att_to_player,att_cautious),
			(party_set_slot,'p_village_18',slot_town_player_relation,0),
			(party_set_slot,'p_village_18',slot_town_import_demand,3),
			(party_set_slot,'p_village_18',slot_town_export_demand,3),
			(party_set_slot,'p_village_18',slot_town_demand,0),
			(party_set_slot,'p_village_18',slot_town_treasury,3600),
			(party_set_slot,'p_village_18',slot_town_garrison_source,'p_village_garrison_source'),
			(party_set_slot,'p_village_18',slot_town_siege_active,0),
			(party_set_slot,'p_village_18',slot_town_under_siege,false),
			(party_set_slot,'p_village_18',slot_town_is_besieged_by,null),
			(party_set_slot,'p_village_18',slot_town_initial_faction,0),
			(party_set_slot,'p_village_18',slot_town_scene_flags,0),
			(party_set_slot,'p_village_18',slot_town_reserve_patrol,-1),
			(party_set_slot,'p_village_18',slot_town_spawn_points,1000),
			(party_set_slot,'p_village_18',slot_party_type,spt_city),
			(party_set_slot,'p_village_18',slot_party_food,5000),
			(party_set_slot,'p_village_18',slot_party_icon,'icon_village'),
			(party_set_slot,'p_village_18',slot_party_icon_state,tis_normal),
			(party_set_slot,'p_village_18',slot_party_ai_state,null),
			(party_set_slot,'p_village_18',slot_party_ai_object,null),
			(party_set_slot,'p_village_18',slot_town_accumulated_rents,0),
			(party_set_slot,'p_village_18',slot_town_accumulated_tariffs,0),
			(party_set_slot,'p_village_18',slot_town_current_improvement,null),
			(party_set_slot,'p_village_18',slot_town_improvement_end_hour,null),
			(party_set_slot,'p_village_18',slot_town_housing_level,1),
			(party_set_slot,'p_village_18',slot_town_irrigation_level,1),
			(party_set_slot,'p_village_18',slot_town_mill_level,1),
			(party_set_slot,'p_village_18',slot_town_raided_by,null),
			(party_set_slot,'p_village_18',slot_town_state,sts_normal),
			(party_set_slot,'p_village_18',slot_town_raid_progress,null),
			(party_set_slot,'p_village_18',slot_town_recover_progress,null),
			(party_set_slot,'p_village_18',slot_town_production_bonus,1),
			(party_set_slot,'p_village_18',slot_town_siege_days,0),
			(party_set_slot,'p_village_18',slot_town_reserve_patrol,null),
			(party_set_slot,'p_village_18',slot_town_trade_good_productions_begin,null),
			(party_set_slot,'p_village_18',slot_town_trade_good_temp_productions_begin,null),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_village_18',slot_town_trade_good_price_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_village_18',slot_town_trade_good_abundance_array,'$return'),
			(party_set_slot,'p_village_18',slot_town_tax_rate,100),
			(party_set_slot,'p_village_18',slot_town_shoen,null),
			(party_set_slot,'p_village_18',slot_town_prefecture_array,null),
			(party_set_slot,'p_village_18',slot_town_reinforcements_a,'pt_village_reinforcements_a'),
			(party_set_slot,'p_village_18',slot_town_reinforcements_b,'pt_village_reinforcements_b'),
			(party_set_slot,'p_village_18',slot_town_reinforcements_c,'pt_village_reinforcements_c'),
			(party_set_slot,'p_village_18',slot_town_population,1000),
			(party_set_slot,'p_village_18',slot_town_population_max,5000),
			(party_set_slot,'p_village_18',slot_town_population_growth_factor,1),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_18',slot_town_demand_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_18',slot_town_storehouse_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_18',slot_town_facility_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_18',slot_town_surplus_array,'$return'),

			(party_set_slot,'p_village_19',slot_town_center,'scn_village'),
			(party_set_slot,'p_village_19',slot_town_castle,0),
			(party_set_slot,'p_village_19',slot_town_inn,0),
			(party_set_slot,'p_village_19',slot_town_store,0),
			(party_set_slot,'p_village_19',slot_town_smithy,0),
			(party_set_slot,'p_village_19',slot_town_capital,hidaka),
			(party_set_slot,'p_village_19',slot_town_dojo,'scn_oya_dojo'),
			(party_set_slot,'p_village_19',slot_town_sensei,'trp_tsunetomo'),
			(party_set_slot,'p_village_19',slot_town_kokujin,'trp_village_19_kokujin'),
			(party_set_slot,'p_village_19',slot_town_innkeeper,'trp_village_19_innkeeper'),
			(party_set_slot,'p_village_19',slot_town_merchant,'trp_village_19_merchant'),
			(party_set_slot,'p_village_19',slot_town_broker,null),
			(party_set_slot,'p_village_19',slot_town_moneychanger,null),
			(party_set_slot,'p_village_19',slot_town_fishmonger,'trp_village_19_fishmonger'),
			(party_set_slot,'p_village_19',slot_town_horse_trader,null),
			(party_set_slot,'p_village_19',slot_town_export_good,itm_kyoto_sake),
			(party_set_slot,'p_village_19',slot_town_export_rate,100),
			(party_set_slot,'p_village_19',slot_town_import_good,itm_salt),
			(party_set_slot,'p_village_19',slot_town_import_rate,100),
			(party_set_slot,'p_village_19',slot_town_terrain,ter_high_valley),
			(party_set_slot,'p_village_19',slot_town_size,ct_village),
			(party_set_slot,'p_village_19',slot_town_mercs,'p_village_19_mercs'),
			(party_set_slot,'p_village_19',slot_town_trade_hub,0),
			(call_script,'script_town_init_trade_dest','p_village_19',hidaka,null,null,null,null,null),
			(party_set_slot,'p_village_19',slot_town_trade_month,7),
			(party_set_slot,'p_village_19',slot_town_att_to_player,att_cautious),
			(party_set_slot,'p_village_19',slot_town_player_relation,0),
			(party_set_slot,'p_village_19',slot_town_import_demand,3),
			(party_set_slot,'p_village_19',slot_town_export_demand,3),
			(party_set_slot,'p_village_19',slot_town_demand,0),
			(party_set_slot,'p_village_19',slot_town_treasury,3600),
			(party_set_slot,'p_village_19',slot_town_garrison_source,'p_village_garrison_source'),
			(party_set_slot,'p_village_19',slot_town_siege_active,0),
			(party_set_slot,'p_village_19',slot_town_under_siege,false),
			(party_set_slot,'p_village_19',slot_town_is_besieged_by,null),
			(party_set_slot,'p_village_19',slot_town_initial_faction,0),
			(party_set_slot,'p_village_19',slot_town_scene_flags,0),
			(party_set_slot,'p_village_19',slot_town_reserve_patrol,-1),
			(party_set_slot,'p_village_19',slot_town_spawn_points,1000),
			(party_set_slot,'p_village_19',slot_party_type,spt_city),
			(party_set_slot,'p_village_19',slot_party_food,5000),
			(party_set_slot,'p_village_19',slot_party_icon,'icon_village'),
			(party_set_slot,'p_village_19',slot_party_icon_state,tis_normal),
			(party_set_slot,'p_village_19',slot_party_ai_state,null),
			(party_set_slot,'p_village_19',slot_party_ai_object,null),
			(party_set_slot,'p_village_19',slot_town_accumulated_rents,0),
			(party_set_slot,'p_village_19',slot_town_accumulated_tariffs,0),
			(party_set_slot,'p_village_19',slot_town_current_improvement,null),
			(party_set_slot,'p_village_19',slot_town_improvement_end_hour,null),
			(party_set_slot,'p_village_19',slot_town_housing_level,1),
			(party_set_slot,'p_village_19',slot_town_irrigation_level,1),
			(party_set_slot,'p_village_19',slot_town_mill_level,1),
			(party_set_slot,'p_village_19',slot_town_raided_by,null),
			(party_set_slot,'p_village_19',slot_town_state,sts_normal),
			(party_set_slot,'p_village_19',slot_town_raid_progress,null),
			(party_set_slot,'p_village_19',slot_town_recover_progress,null),
			(party_set_slot,'p_village_19',slot_town_production_bonus,1),
			(party_set_slot,'p_village_19',slot_town_siege_days,0),
			(party_set_slot,'p_village_19',slot_town_reserve_patrol,null),
			(party_set_slot,'p_village_19',slot_town_trade_good_productions_begin,null),
			(party_set_slot,'p_village_19',slot_town_trade_good_temp_productions_begin,null),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_village_19',slot_town_trade_good_price_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_village_19',slot_town_trade_good_abundance_array,'$return'),
			(party_set_slot,'p_village_19',slot_town_tax_rate,100),
			(party_set_slot,'p_village_19',slot_town_shoen,null),
			(party_set_slot,'p_village_19',slot_town_prefecture_array,null),
			(party_set_slot,'p_village_19',slot_town_reinforcements_a,'pt_village_reinforcements_a'),
			(party_set_slot,'p_village_19',slot_town_reinforcements_b,'pt_village_reinforcements_b'),
			(party_set_slot,'p_village_19',slot_town_reinforcements_c,'pt_village_reinforcements_c'),
			(party_set_slot,'p_village_19',slot_town_population,1000),
			(party_set_slot,'p_village_19',slot_town_population_max,5000),
			(party_set_slot,'p_village_19',slot_town_population_growth_factor,1),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_19',slot_town_demand_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_19',slot_town_storehouse_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_19',slot_town_facility_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_19',slot_town_surplus_array,'$return'),

			(party_set_slot,'p_village_20',slot_town_center,'scn_village'),
			(party_set_slot,'p_village_20',slot_town_castle,0),
			(party_set_slot,'p_village_20',slot_town_inn,0),
			(party_set_slot,'p_village_20',slot_town_store,0),
			(party_set_slot,'p_village_20',slot_town_smithy,0),
			(party_set_slot,'p_village_20',slot_town_capital,hidaka),
			(party_set_slot,'p_village_20',slot_town_dojo,0),
			(party_set_slot,'p_village_20',slot_town_sensei,-1),
			(party_set_slot,'p_village_20',slot_town_kokujin,'trp_village_20_kokujin'),
			(party_set_slot,'p_village_20',slot_town_innkeeper,'trp_village_20_innkeeper'),
			(party_set_slot,'p_village_20',slot_town_merchant,'trp_village_20_merchant'),
			(party_set_slot,'p_village_20',slot_town_broker,null),
			(party_set_slot,'p_village_20',slot_town_moneychanger,null),
			(party_set_slot,'p_village_20',slot_town_fishmonger,'trp_village_20_fishmonger'),
			(party_set_slot,'p_village_20',slot_town_horse_trader,null),
			(party_set_slot,'p_village_20',slot_town_export_good,itm_kyoto_sake),
			(party_set_slot,'p_village_20',slot_town_export_rate,100),
			(party_set_slot,'p_village_20',slot_town_import_good,itm_salt),
			(party_set_slot,'p_village_20',slot_town_import_rate,100),
			(party_set_slot,'p_village_20',slot_town_terrain,ter_high_valley),
			(party_set_slot,'p_village_20',slot_town_size,ct_small_village),
			(party_set_slot,'p_village_20',slot_town_mercs,'p_village_20_mercs'),
			(party_set_slot,'p_village_20',slot_town_trade_hub,0),
			(call_script,'script_town_init_trade_dest','p_village_20',hidaka,null,null,null,null,null),
			(party_set_slot,'p_village_20',slot_town_trade_month,10),
			(party_set_slot,'p_village_20',slot_town_att_to_player,att_cautious),
			(party_set_slot,'p_village_20',slot_town_player_relation,0),
			(party_set_slot,'p_village_20',slot_town_import_demand,3),
			(party_set_slot,'p_village_20',slot_town_export_demand,3),
			(party_set_slot,'p_village_20',slot_town_demand,0),
			(party_set_slot,'p_village_20',slot_town_treasury,3600),
			(party_set_slot,'p_village_20',slot_town_garrison_source,'p_village_garrison_source'),
			(party_set_slot,'p_village_20',slot_town_siege_active,0),
			(party_set_slot,'p_village_20',slot_town_under_siege,false),
			(party_set_slot,'p_village_20',slot_town_is_besieged_by,null),
			(party_set_slot,'p_village_20',slot_town_initial_faction,0),
			(party_set_slot,'p_village_20',slot_town_scene_flags,0),
			(party_set_slot,'p_village_20',slot_town_reserve_patrol,-1),
			(party_set_slot,'p_village_20',slot_town_spawn_points,1000),
			(party_set_slot,'p_village_20',slot_party_type,spt_city),
			(party_set_slot,'p_village_20',slot_party_food,5000),
			(party_set_slot,'p_village_20',slot_party_icon,'icon_village'),
			(party_set_slot,'p_village_20',slot_party_icon_state,tis_normal),
			(party_set_slot,'p_village_20',slot_party_ai_state,null),
			(party_set_slot,'p_village_20',slot_party_ai_object,null),
			(party_set_slot,'p_village_20',slot_town_accumulated_rents,0),
			(party_set_slot,'p_village_20',slot_town_accumulated_tariffs,0),
			(party_set_slot,'p_village_20',slot_town_current_improvement,null),
			(party_set_slot,'p_village_20',slot_town_improvement_end_hour,null),
			(party_set_slot,'p_village_20',slot_town_housing_level,1),
			(party_set_slot,'p_village_20',slot_town_irrigation_level,1),
			(party_set_slot,'p_village_20',slot_town_mill_level,1),
			(party_set_slot,'p_village_20',slot_town_raided_by,null),
			(party_set_slot,'p_village_20',slot_town_state,sts_normal),
			(party_set_slot,'p_village_20',slot_town_raid_progress,null),
			(party_set_slot,'p_village_20',slot_town_recover_progress,null),
			(party_set_slot,'p_village_20',slot_town_production_bonus,1),
			(party_set_slot,'p_village_20',slot_town_siege_days,0),
			(party_set_slot,'p_village_20',slot_town_reserve_patrol,null),
			(party_set_slot,'p_village_20',slot_town_trade_good_productions_begin,null),
			(party_set_slot,'p_village_20',slot_town_trade_good_temp_productions_begin,null),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_village_20',slot_town_trade_good_price_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_village_20',slot_town_trade_good_abundance_array,'$return'),
			(party_set_slot,'p_village_20',slot_town_tax_rate,100),
			(party_set_slot,'p_village_20',slot_town_shoen,null),
			(party_set_slot,'p_village_20',slot_town_prefecture_array,null),
			(party_set_slot,'p_village_20',slot_town_reinforcements_a,'pt_village_reinforcements_a'),
			(party_set_slot,'p_village_20',slot_town_reinforcements_b,'pt_village_reinforcements_b'),
			(party_set_slot,'p_village_20',slot_town_reinforcements_c,'pt_village_reinforcements_c'),
			(party_set_slot,'p_village_20',slot_town_population,1000),
			(party_set_slot,'p_village_20',slot_town_population_max,5000),
			(party_set_slot,'p_village_20',slot_town_population_growth_factor,1),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_20',slot_town_demand_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_20',slot_town_storehouse_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_20',slot_town_facility_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_20',slot_town_surplus_array,'$return'),

			(party_set_slot,'p_village_21',slot_town_center,'scn_village'),
			(party_set_slot,'p_village_21',slot_town_castle,0),
			(party_set_slot,'p_village_21',slot_town_inn,0),
			(party_set_slot,'p_village_21',slot_town_store,0),
			(party_set_slot,'p_village_21',slot_town_smithy,0),
			(party_set_slot,'p_village_21',slot_town_capital,hidaka),
			(party_set_slot,'p_village_21',slot_town_dojo,0),
			(party_set_slot,'p_village_21',slot_town_sensei,-1),
			(party_set_slot,'p_village_21',slot_town_kokujin,'trp_village_21_kokujin'),
			(party_set_slot,'p_village_21',slot_town_innkeeper,'trp_village_21_innkeeper'),
			(party_set_slot,'p_village_21',slot_town_merchant,'trp_village_21_merchant'),
			(party_set_slot,'p_village_21',slot_town_broker,null),
			(party_set_slot,'p_village_21',slot_town_moneychanger,null),
			(party_set_slot,'p_village_21',slot_town_fishmonger,'trp_village_21_fishmonger'),
			(party_set_slot,'p_village_21',slot_town_horse_trader,null),
			(party_set_slot,'p_village_21',slot_town_export_good,itm_kyoto_sake),
			(party_set_slot,'p_village_21',slot_town_export_rate,100),
			(party_set_slot,'p_village_21',slot_town_import_good,itm_salt),
			(party_set_slot,'p_village_21',slot_town_import_rate,100),
			(party_set_slot,'p_village_21',slot_town_terrain,ter_seaside),
			(party_set_slot,'p_village_21',slot_town_size,ct_small_village),
			(party_set_slot,'p_village_21',slot_town_mercs,'p_village_21_mercs'),
			(party_set_slot,'p_village_21',slot_town_trade_hub,0),
			(call_script,'script_town_init_trade_dest','p_village_21',hidaka,null,null,null,null,null),
			(party_set_slot,'p_village_21',slot_town_trade_month,4),
			(party_set_slot,'p_village_21',slot_town_att_to_player,att_cautious),
			(party_set_slot,'p_village_21',slot_town_player_relation,0),
			(party_set_slot,'p_village_21',slot_town_import_demand,3),
			(party_set_slot,'p_village_21',slot_town_export_demand,3),
			(party_set_slot,'p_village_21',slot_town_demand,0),
			(party_set_slot,'p_village_21',slot_town_treasury,3600),
			(party_set_slot,'p_village_21',slot_town_garrison_source,'p_village_garrison_source'),
			(party_set_slot,'p_village_21',slot_town_siege_active,0),
			(party_set_slot,'p_village_21',slot_town_under_siege,false),
			(party_set_slot,'p_village_21',slot_town_is_besieged_by,null),
			(party_set_slot,'p_village_21',slot_town_initial_faction,0),
			(party_set_slot,'p_village_21',slot_town_scene_flags,0),
			(party_set_slot,'p_village_21',slot_town_reserve_patrol,-1),
			(party_set_slot,'p_village_21',slot_town_spawn_points,1000),
			(party_set_slot,'p_village_21',slot_party_type,spt_city),
			(party_set_slot,'p_village_21',slot_party_food,5000),
			(party_set_slot,'p_village_21',slot_party_icon,'icon_village'),
			(party_set_slot,'p_village_21',slot_party_icon_state,tis_normal),
			(party_set_slot,'p_village_21',slot_party_ai_state,null),
			(party_set_slot,'p_village_21',slot_party_ai_object,null),
			(party_set_slot,'p_village_21',slot_town_accumulated_rents,0),
			(party_set_slot,'p_village_21',slot_town_accumulated_tariffs,0),
			(party_set_slot,'p_village_21',slot_town_current_improvement,null),
			(party_set_slot,'p_village_21',slot_town_improvement_end_hour,null),
			(party_set_slot,'p_village_21',slot_town_housing_level,1),
			(party_set_slot,'p_village_21',slot_town_irrigation_level,1),
			(party_set_slot,'p_village_21',slot_town_mill_level,1),
			(party_set_slot,'p_village_21',slot_town_raided_by,null),
			(party_set_slot,'p_village_21',slot_town_state,sts_normal),
			(party_set_slot,'p_village_21',slot_town_raid_progress,null),
			(party_set_slot,'p_village_21',slot_town_recover_progress,null),
			(party_set_slot,'p_village_21',slot_town_production_bonus,1),
			(party_set_slot,'p_village_21',slot_town_siege_days,0),
			(party_set_slot,'p_village_21',slot_town_reserve_patrol,null),
			(party_set_slot,'p_village_21',slot_town_trade_good_productions_begin,null),
			(party_set_slot,'p_village_21',slot_town_trade_good_temp_productions_begin,null),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_village_21',slot_town_trade_good_price_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_village_21',slot_town_trade_good_abundance_array,'$return'),
			(party_set_slot,'p_village_21',slot_town_tax_rate,100),
			(party_set_slot,'p_village_21',slot_town_shoen,null),
			(party_set_slot,'p_village_21',slot_town_prefecture_array,null),
			(party_set_slot,'p_village_21',slot_town_reinforcements_a,'pt_village_reinforcements_a'),
			(party_set_slot,'p_village_21',slot_town_reinforcements_b,'pt_village_reinforcements_b'),
			(party_set_slot,'p_village_21',slot_town_reinforcements_c,'pt_village_reinforcements_c'),
			(party_set_slot,'p_village_21',slot_town_population,1000),
			(party_set_slot,'p_village_21',slot_town_population_max,5000),
			(party_set_slot,'p_village_21',slot_town_population_growth_factor,1),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_21',slot_town_demand_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_21',slot_town_storehouse_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_21',slot_town_facility_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_21',slot_town_surplus_array,'$return'),

			(party_set_slot,'p_village_22',slot_town_center,'scn_village'),
			(party_set_slot,'p_village_22',slot_town_castle,0),
			(party_set_slot,'p_village_22',slot_town_inn,0),
			(party_set_slot,'p_village_22',slot_town_store,0),
			(party_set_slot,'p_village_22',slot_town_smithy,0),
			(party_set_slot,'p_village_22',slot_town_capital,wakayama),
			(party_set_slot,'p_village_22',slot_town_dojo,0),
			(party_set_slot,'p_village_22',slot_town_sensei,-1),
			(party_set_slot,'p_village_22',slot_town_kokujin,'trp_village_22_kokujin'),
			(party_set_slot,'p_village_22',slot_town_innkeeper,'trp_village_22_innkeeper'),
			(party_set_slot,'p_village_22',slot_town_merchant,'trp_village_22_merchant'),
			(party_set_slot,'p_village_22',slot_town_broker,null),
			(party_set_slot,'p_village_22',slot_town_moneychanger,null),
			(party_set_slot,'p_village_22',slot_town_fishmonger,'trp_village_22_fishmonger'),
			(party_set_slot,'p_village_22',slot_town_horse_trader,null),
			(party_set_slot,'p_village_22',slot_town_export_good,itm_kyoto_sake),
			(party_set_slot,'p_village_22',slot_town_export_rate,100),
			(party_set_slot,'p_village_22',slot_town_import_good,itm_salt),
			(party_set_slot,'p_village_22',slot_town_import_rate,100),
			(party_set_slot,'p_village_22',slot_town_terrain,ter_high_valley),
			(party_set_slot,'p_village_22',slot_town_size,ct_large_village),
			(party_set_slot,'p_village_22',slot_town_mercs,'p_village_22_mercs'),
			(party_set_slot,'p_village_22',slot_town_trade_hub,0),
			(call_script,'script_town_init_trade_dest','p_village_22',nara,null,null,null,null,null),
			(party_set_slot,'p_village_22',slot_town_trade_month,7),
			(party_set_slot,'p_village_22',slot_town_att_to_player,att_cautious),
			(party_set_slot,'p_village_22',slot_town_player_relation,0),
			(party_set_slot,'p_village_22',slot_town_import_demand,3),
			(party_set_slot,'p_village_22',slot_town_export_demand,3),
			(party_set_slot,'p_village_22',slot_town_demand,0),
			(party_set_slot,'p_village_22',slot_town_treasury,3600),
			(party_set_slot,'p_village_22',slot_town_garrison_source,'p_village_garrison_source'),
			(party_set_slot,'p_village_22',slot_town_siege_active,0),
			(party_set_slot,'p_village_22',slot_town_under_siege,false),
			(party_set_slot,'p_village_22',slot_town_is_besieged_by,null),
			(party_set_slot,'p_village_22',slot_town_initial_faction,0),
			(party_set_slot,'p_village_22',slot_town_scene_flags,0),
			(party_set_slot,'p_village_22',slot_town_reserve_patrol,-1),
			(party_set_slot,'p_village_22',slot_town_spawn_points,1000),
			(party_set_slot,'p_village_22',slot_party_type,spt_city),
			(party_set_slot,'p_village_22',slot_party_food,5000),
			(party_set_slot,'p_village_22',slot_party_icon,'icon_village'),
			(party_set_slot,'p_village_22',slot_party_icon_state,tis_normal),
			(party_set_slot,'p_village_22',slot_party_ai_state,null),
			(party_set_slot,'p_village_22',slot_party_ai_object,null),
			(party_set_slot,'p_village_22',slot_town_accumulated_rents,0),
			(party_set_slot,'p_village_22',slot_town_accumulated_tariffs,0),
			(party_set_slot,'p_village_22',slot_town_current_improvement,null),
			(party_set_slot,'p_village_22',slot_town_improvement_end_hour,null),
			(party_set_slot,'p_village_22',slot_town_housing_level,1),
			(party_set_slot,'p_village_22',slot_town_irrigation_level,1),
			(party_set_slot,'p_village_22',slot_town_mill_level,1),
			(party_set_slot,'p_village_22',slot_town_raided_by,null),
			(party_set_slot,'p_village_22',slot_town_state,sts_normal),
			(party_set_slot,'p_village_22',slot_town_raid_progress,null),
			(party_set_slot,'p_village_22',slot_town_recover_progress,null),
			(party_set_slot,'p_village_22',slot_town_production_bonus,1),
			(party_set_slot,'p_village_22',slot_town_siege_days,0),
			(party_set_slot,'p_village_22',slot_town_reserve_patrol,null),
			(party_set_slot,'p_village_22',slot_town_trade_good_productions_begin,null),
			(party_set_slot,'p_village_22',slot_town_trade_good_temp_productions_begin,null),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_village_22',slot_town_trade_good_price_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_village_22',slot_town_trade_good_abundance_array,'$return'),
			(party_set_slot,'p_village_22',slot_town_tax_rate,100),
			(party_set_slot,'p_village_22',slot_town_shoen,null),
			(party_set_slot,'p_village_22',slot_town_prefecture_array,null),
			(party_set_slot,'p_village_22',slot_town_reinforcements_a,'pt_village_reinforcements_a'),
			(party_set_slot,'p_village_22',slot_town_reinforcements_b,'pt_village_reinforcements_b'),
			(party_set_slot,'p_village_22',slot_town_reinforcements_c,'pt_village_reinforcements_c'),
			(party_set_slot,'p_village_22',slot_town_population,1000),
			(party_set_slot,'p_village_22',slot_town_population_max,5000),
			(party_set_slot,'p_village_22',slot_town_population_growth_factor,1),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_22',slot_town_demand_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_22',slot_town_storehouse_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_22',slot_town_facility_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_22',slot_town_surplus_array,'$return'),

			(party_set_slot,'p_village_23',slot_town_center,'scn_village'),
			(party_set_slot,'p_village_23',slot_town_castle,0),
			(party_set_slot,'p_village_23',slot_town_inn,0),
			(party_set_slot,'p_village_23',slot_town_store,0),
			(party_set_slot,'p_village_23',slot_town_smithy,0),
			(party_set_slot,'p_village_23',slot_town_capital,fukuchiyama),
			(party_set_slot,'p_village_23',slot_town_dojo,0),
			(party_set_slot,'p_village_23',slot_town_sensei,-1),
			(party_set_slot,'p_village_23',slot_town_kokujin,'trp_village_23_kokujin'),
			(party_set_slot,'p_village_23',slot_town_innkeeper,'trp_village_23_innkeeper'),
			(party_set_slot,'p_village_23',slot_town_merchant,'trp_village_23_merchant'),
			(party_set_slot,'p_village_23',slot_town_broker,null),
			(party_set_slot,'p_village_23',slot_town_moneychanger,null),
			(party_set_slot,'p_village_23',slot_town_fishmonger,'trp_village_23_fishmonger'),
			(party_set_slot,'p_village_23',slot_town_horse_trader,null),
			(party_set_slot,'p_village_23',slot_town_export_good,itm_kyoto_sake),
			(party_set_slot,'p_village_23',slot_town_export_rate,100),
			(party_set_slot,'p_village_23',slot_town_import_good,itm_salt),
			(party_set_slot,'p_village_23',slot_town_import_rate,100),
			(party_set_slot,'p_village_23',slot_town_terrain,ter_high_valley),
			(party_set_slot,'p_village_23',slot_town_size,ct_large_village),
			(party_set_slot,'p_village_23',slot_town_mercs,'p_village_23_mercs'),
			(party_set_slot,'p_village_23',slot_town_trade_hub,0),
			(call_script,'script_town_init_trade_dest','p_village_23',sasayama,null,null,null,null,null),
			(party_set_slot,'p_village_23',slot_town_trade_month,10),
			(party_set_slot,'p_village_23',slot_town_att_to_player,att_cautious),
			(party_set_slot,'p_village_23',slot_town_player_relation,0),
			(party_set_slot,'p_village_23',slot_town_import_demand,3),
			(party_set_slot,'p_village_23',slot_town_export_demand,3),
			(party_set_slot,'p_village_23',slot_town_demand,0),
			(party_set_slot,'p_village_23',slot_town_treasury,3600),
			(party_set_slot,'p_village_23',slot_town_garrison_source,'p_village_garrison_source'),
			(party_set_slot,'p_village_23',slot_town_siege_active,0),
			(party_set_slot,'p_village_23',slot_town_under_siege,false),
			(party_set_slot,'p_village_23',slot_town_is_besieged_by,null),
			(party_set_slot,'p_village_23',slot_town_initial_faction,0),
			(party_set_slot,'p_village_23',slot_town_scene_flags,0),
			(party_set_slot,'p_village_23',slot_town_reserve_patrol,-1),
			(party_set_slot,'p_village_23',slot_town_spawn_points,1000),
			(party_set_slot,'p_village_23',slot_party_type,spt_city),
			(party_set_slot,'p_village_23',slot_party_food,5000),
			(party_set_slot,'p_village_23',slot_party_icon,'icon_village'),
			(party_set_slot,'p_village_23',slot_party_icon_state,tis_normal),
			(party_set_slot,'p_village_23',slot_party_ai_state,null),
			(party_set_slot,'p_village_23',slot_party_ai_object,null),
			(party_set_slot,'p_village_23',slot_town_accumulated_rents,0),
			(party_set_slot,'p_village_23',slot_town_accumulated_tariffs,0),
			(party_set_slot,'p_village_23',slot_town_current_improvement,null),
			(party_set_slot,'p_village_23',slot_town_improvement_end_hour,null),
			(party_set_slot,'p_village_23',slot_town_housing_level,1),
			(party_set_slot,'p_village_23',slot_town_irrigation_level,1),
			(party_set_slot,'p_village_23',slot_town_mill_level,1),
			(party_set_slot,'p_village_23',slot_town_raided_by,null),
			(party_set_slot,'p_village_23',slot_town_state,sts_normal),
			(party_set_slot,'p_village_23',slot_town_raid_progress,null),
			(party_set_slot,'p_village_23',slot_town_recover_progress,null),
			(party_set_slot,'p_village_23',slot_town_production_bonus,1),
			(party_set_slot,'p_village_23',slot_town_siege_days,0),
			(party_set_slot,'p_village_23',slot_town_reserve_patrol,null),
			(party_set_slot,'p_village_23',slot_town_trade_good_productions_begin,null),
			(party_set_slot,'p_village_23',slot_town_trade_good_temp_productions_begin,null),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_village_23',slot_town_trade_good_price_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_village_23',slot_town_trade_good_abundance_array,'$return'),
			(party_set_slot,'p_village_23',slot_town_tax_rate,100),
			(party_set_slot,'p_village_23',slot_town_shoen,null),
			(party_set_slot,'p_village_23',slot_town_prefecture_array,null),
			(party_set_slot,'p_village_23',slot_town_reinforcements_a,'pt_village_reinforcements_a'),
			(party_set_slot,'p_village_23',slot_town_reinforcements_b,'pt_village_reinforcements_b'),
			(party_set_slot,'p_village_23',slot_town_reinforcements_c,'pt_village_reinforcements_c'),
			(party_set_slot,'p_village_23',slot_town_population,1000),
			(party_set_slot,'p_village_23',slot_town_population_max,5000),
			(party_set_slot,'p_village_23',slot_town_population_growth_factor,1),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_23',slot_town_demand_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_23',slot_town_storehouse_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_23',slot_town_facility_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_23',slot_town_surplus_array,'$return'),

			(party_set_slot,'p_village_24',slot_town_center,'scn_village'),
			(party_set_slot,'p_village_24',slot_town_castle,0),
			(party_set_slot,'p_village_24',slot_town_inn,0),
			(party_set_slot,'p_village_24',slot_town_store,0),
			(party_set_slot,'p_village_24',slot_town_smithy,0),
			(party_set_slot,'p_village_24',slot_town_capital,nara),
			(party_set_slot,'p_village_24',slot_town_dojo,0),
			(party_set_slot,'p_village_24',slot_town_sensei,-1),
			(party_set_slot,'p_village_24',slot_town_kokujin,'trp_village_24_kokujin'),
			(party_set_slot,'p_village_24',slot_town_innkeeper,'trp_village_24_innkeeper'),
			(party_set_slot,'p_village_24',slot_town_merchant,'trp_village_24_merchant'),
			(party_set_slot,'p_village_24',slot_town_broker,null),
			(party_set_slot,'p_village_24',slot_town_moneychanger,null),
			(party_set_slot,'p_village_24',slot_town_fishmonger,'trp_village_24_fishmonger'),
			(party_set_slot,'p_village_24',slot_town_horse_trader,null),
			(party_set_slot,'p_village_24',slot_town_export_good,itm_kyoto_sake),
			(party_set_slot,'p_village_24',slot_town_export_rate,100),
			(party_set_slot,'p_village_24',slot_town_import_good,itm_salt),
			(party_set_slot,'p_village_24',slot_town_import_rate,100),
			(party_set_slot,'p_village_24',slot_town_terrain,ter_low_valley),
			(party_set_slot,'p_village_24',slot_town_size,ct_village),
			(party_set_slot,'p_village_24',slot_town_mercs,'p_village_24_mercs'),
			(party_set_slot,'p_village_24',slot_town_trade_hub,0),
			(call_script,'script_town_init_trade_dest','p_village_24',uji,null,null,null,null,null),
			(party_set_slot,'p_village_24',slot_town_trade_month,4),
			(party_set_slot,'p_village_24',slot_town_att_to_player,att_cautious),
			(party_set_slot,'p_village_24',slot_town_player_relation,0),
			(party_set_slot,'p_village_24',slot_town_import_demand,3),
			(party_set_slot,'p_village_24',slot_town_export_demand,3),
			(party_set_slot,'p_village_24',slot_town_demand,0),
			(party_set_slot,'p_village_24',slot_town_treasury,3600),
			(party_set_slot,'p_village_24',slot_town_garrison_source,'p_village_garrison_source'),
			(party_set_slot,'p_village_24',slot_town_siege_active,0),
			(party_set_slot,'p_village_24',slot_town_under_siege,false),
			(party_set_slot,'p_village_24',slot_town_is_besieged_by,null),
			(party_set_slot,'p_village_24',slot_town_initial_faction,0),
			(party_set_slot,'p_village_24',slot_town_scene_flags,0),
			(party_set_slot,'p_village_24',slot_town_reserve_patrol,-1),
			(party_set_slot,'p_village_24',slot_town_spawn_points,1000),
			(party_set_slot,'p_village_24',slot_party_type,spt_city),
			(party_set_slot,'p_village_24',slot_party_food,5000),
			(party_set_slot,'p_village_24',slot_party_icon,'icon_village'),
			(party_set_slot,'p_village_24',slot_party_icon_state,tis_normal),
			(party_set_slot,'p_village_24',slot_party_ai_state,null),
			(party_set_slot,'p_village_24',slot_party_ai_object,null),
			(party_set_slot,'p_village_24',slot_town_accumulated_rents,0),
			(party_set_slot,'p_village_24',slot_town_accumulated_tariffs,0),
			(party_set_slot,'p_village_24',slot_town_current_improvement,null),
			(party_set_slot,'p_village_24',slot_town_improvement_end_hour,null),
			(party_set_slot,'p_village_24',slot_town_housing_level,1),
			(party_set_slot,'p_village_24',slot_town_irrigation_level,1),
			(party_set_slot,'p_village_24',slot_town_mill_level,1),
			(party_set_slot,'p_village_24',slot_town_raided_by,null),
			(party_set_slot,'p_village_24',slot_town_state,sts_normal),
			(party_set_slot,'p_village_24',slot_town_raid_progress,null),
			(party_set_slot,'p_village_24',slot_town_recover_progress,null),
			(party_set_slot,'p_village_24',slot_town_production_bonus,1),
			(party_set_slot,'p_village_24',slot_town_siege_days,0),
			(party_set_slot,'p_village_24',slot_town_reserve_patrol,null),
			(party_set_slot,'p_village_24',slot_town_trade_good_productions_begin,null),
			(party_set_slot,'p_village_24',slot_town_trade_good_temp_productions_begin,null),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_village_24',slot_town_trade_good_price_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_village_24',slot_town_trade_good_abundance_array,'$return'),
			(party_set_slot,'p_village_24',slot_town_tax_rate,100),
			(party_set_slot,'p_village_24',slot_town_shoen,null),
			(party_set_slot,'p_village_24',slot_town_prefecture_array,null),
			(party_set_slot,'p_village_24',slot_town_reinforcements_a,'pt_village_reinforcements_a'),
			(party_set_slot,'p_village_24',slot_town_reinforcements_b,'pt_village_reinforcements_b'),
			(party_set_slot,'p_village_24',slot_town_reinforcements_c,'pt_village_reinforcements_c'),
			(party_set_slot,'p_village_24',slot_town_population,1000),
			(party_set_slot,'p_village_24',slot_town_population_max,5000),
			(party_set_slot,'p_village_24',slot_town_population_growth_factor,1),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_24',slot_town_demand_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_24',slot_town_storehouse_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_24',slot_town_facility_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_24',slot_town_surplus_array,'$return'),

			(party_set_slot,'p_village_25',slot_town_center,'scn_village'),
			(party_set_slot,'p_village_25',slot_town_castle,0),
			(party_set_slot,'p_village_25',slot_town_inn,0),
			(party_set_slot,'p_village_25',slot_town_store,0),
			(party_set_slot,'p_village_25',slot_town_smithy,0),
			(party_set_slot,'p_village_25',slot_town_capital,hikone),
			(party_set_slot,'p_village_25',slot_town_dojo,0),
			(party_set_slot,'p_village_25',slot_town_sensei,-1),
			(party_set_slot,'p_village_25',slot_town_kokujin,'trp_village_25_kokujin'),
			(party_set_slot,'p_village_25',slot_town_innkeeper,'trp_village_25_innkeeper'),
			(party_set_slot,'p_village_25',slot_town_merchant,'trp_village_25_merchant'),
			(party_set_slot,'p_village_25',slot_town_broker,null),
			(party_set_slot,'p_village_25',slot_town_moneychanger,null),
			(party_set_slot,'p_village_25',slot_town_fishmonger,'trp_village_25_fishmonger'),
			(party_set_slot,'p_village_25',slot_town_horse_trader,null),
			(party_set_slot,'p_village_25',slot_town_export_good,itm_kyoto_sake),
			(party_set_slot,'p_village_25',slot_town_export_rate,100),
			(party_set_slot,'p_village_25',slot_town_import_good,itm_salt),
			(party_set_slot,'p_village_25',slot_town_import_rate,100),
			(party_set_slot,'p_village_25',slot_town_terrain,ter_lakeside),
			(party_set_slot,'p_village_25',slot_town_size,ct_village),
			(party_set_slot,'p_village_25',slot_town_mercs,'p_village_25_mercs'),
			(party_set_slot,'p_village_25',slot_town_trade_hub,0),
			(call_script,'script_town_init_trade_dest','p_village_25',moriyama,null,null,null,null,null),
			(party_set_slot,'p_village_25',slot_town_trade_month,7),
			(party_set_slot,'p_village_25',slot_town_att_to_player,att_cautious),
			(party_set_slot,'p_village_25',slot_town_player_relation,0),
			(party_set_slot,'p_village_25',slot_town_import_demand,3),
			(party_set_slot,'p_village_25',slot_town_export_demand,3),
			(party_set_slot,'p_village_25',slot_town_demand,0),
			(party_set_slot,'p_village_25',slot_town_treasury,3600),
			(party_set_slot,'p_village_25',slot_town_garrison_source,'p_village_garrison_source'),
			(party_set_slot,'p_village_25',slot_town_siege_active,0),
			(party_set_slot,'p_village_25',slot_town_under_siege,false),
			(party_set_slot,'p_village_25',slot_town_is_besieged_by,null),
			(party_set_slot,'p_village_25',slot_town_initial_faction,0),
			(party_set_slot,'p_village_25',slot_town_scene_flags,0),
			(party_set_slot,'p_village_25',slot_town_reserve_patrol,-1),
			(party_set_slot,'p_village_25',slot_town_spawn_points,1000),
			(party_set_slot,'p_village_25',slot_party_type,spt_city),
			(party_set_slot,'p_village_25',slot_party_food,5000),
			(party_set_slot,'p_village_25',slot_party_icon,'icon_village'),
			(party_set_slot,'p_village_25',slot_party_icon_state,tis_normal),
			(party_set_slot,'p_village_25',slot_party_ai_state,null),
			(party_set_slot,'p_village_25',slot_party_ai_object,null),
			(party_set_slot,'p_village_25',slot_town_accumulated_rents,0),
			(party_set_slot,'p_village_25',slot_town_accumulated_tariffs,0),
			(party_set_slot,'p_village_25',slot_town_current_improvement,null),
			(party_set_slot,'p_village_25',slot_town_improvement_end_hour,null),
			(party_set_slot,'p_village_25',slot_town_housing_level,1),
			(party_set_slot,'p_village_25',slot_town_irrigation_level,1),
			(party_set_slot,'p_village_25',slot_town_mill_level,1),
			(party_set_slot,'p_village_25',slot_town_raided_by,null),
			(party_set_slot,'p_village_25',slot_town_state,sts_normal),
			(party_set_slot,'p_village_25',slot_town_raid_progress,null),
			(party_set_slot,'p_village_25',slot_town_recover_progress,null),
			(party_set_slot,'p_village_25',slot_town_production_bonus,1),
			(party_set_slot,'p_village_25',slot_town_siege_days,0),
			(party_set_slot,'p_village_25',slot_town_reserve_patrol,null),
			(party_set_slot,'p_village_25',slot_town_trade_good_productions_begin,null),
			(party_set_slot,'p_village_25',slot_town_trade_good_temp_productions_begin,null),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_village_25',slot_town_trade_good_price_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_village_25',slot_town_trade_good_abundance_array,'$return'),
			(party_set_slot,'p_village_25',slot_town_tax_rate,100),
			(party_set_slot,'p_village_25',slot_town_shoen,null),
			(party_set_slot,'p_village_25',slot_town_prefecture_array,null),
			(party_set_slot,'p_village_25',slot_town_reinforcements_a,'pt_village_reinforcements_a'),
			(party_set_slot,'p_village_25',slot_town_reinforcements_b,'pt_village_reinforcements_b'),
			(party_set_slot,'p_village_25',slot_town_reinforcements_c,'pt_village_reinforcements_c'),
			(party_set_slot,'p_village_25',slot_town_population,1000),
			(party_set_slot,'p_village_25',slot_town_population_max,5000),
			(party_set_slot,'p_village_25',slot_town_population_growth_factor,1),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_25',slot_town_demand_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_25',slot_town_storehouse_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_25',slot_town_facility_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_25',slot_town_surplus_array,'$return'),

			(party_set_slot,'p_village_26',slot_town_center,'scn_village'),
			(party_set_slot,'p_village_26',slot_town_castle,0),
			(party_set_slot,'p_village_26',slot_town_inn,0),
			(party_set_slot,'p_village_26',slot_town_store,0),
			(party_set_slot,'p_village_26',slot_town_smithy,0),
			(party_set_slot,'p_village_26',slot_town_capital,tsuruga),
			(party_set_slot,'p_village_26',slot_town_dojo,0),
			(party_set_slot,'p_village_26',slot_town_sensei,-1),
			(party_set_slot,'p_village_26',slot_town_kokujin,'trp_village_26_kokujin'),
			(party_set_slot,'p_village_26',slot_town_innkeeper,'trp_village_26_innkeeper'),
			(party_set_slot,'p_village_26',slot_town_merchant,'trp_village_26_merchant'),
			(party_set_slot,'p_village_26',slot_town_broker,null),
			(party_set_slot,'p_village_26',slot_town_moneychanger,null),
			(party_set_slot,'p_village_26',slot_town_fishmonger,'trp_village_26_fishmonger'),
			(party_set_slot,'p_village_26',slot_town_horse_trader,null),
			(party_set_slot,'p_village_26',slot_town_export_good,itm_kyoto_sake),
			(party_set_slot,'p_village_26',slot_town_export_rate,100),
			(party_set_slot,'p_village_26',slot_town_import_good,itm_salt),
			(party_set_slot,'p_village_26',slot_town_import_rate,100),
			(party_set_slot,'p_village_26',slot_town_terrain,ter_lakeside),
			(party_set_slot,'p_village_26',slot_town_size,ct_village),
			(party_set_slot,'p_village_26',slot_town_mercs,'p_village_26_mercs'),
			(party_set_slot,'p_village_26',slot_town_trade_hub,0),
			(call_script,'script_town_init_trade_dest','p_village_26',hikone,null,null,null,null,null),
			(party_set_slot,'p_village_26',slot_town_trade_month,10),
			(party_set_slot,'p_village_26',slot_town_att_to_player,att_cautious),
			(party_set_slot,'p_village_26',slot_town_player_relation,0),
			(party_set_slot,'p_village_26',slot_town_import_demand,3),
			(party_set_slot,'p_village_26',slot_town_export_demand,3),
			(party_set_slot,'p_village_26',slot_town_demand,0),
			(party_set_slot,'p_village_26',slot_town_treasury,3600),
			(party_set_slot,'p_village_26',slot_town_garrison_source,'p_village_garrison_source'),
			(party_set_slot,'p_village_26',slot_town_siege_active,0),
			(party_set_slot,'p_village_26',slot_town_under_siege,false),
			(party_set_slot,'p_village_26',slot_town_is_besieged_by,null),
			(party_set_slot,'p_village_26',slot_town_initial_faction,0),
			(party_set_slot,'p_village_26',slot_town_scene_flags,0),
			(party_set_slot,'p_village_26',slot_town_reserve_patrol,-1),
			(party_set_slot,'p_village_26',slot_town_spawn_points,1000),
			(party_set_slot,'p_village_26',slot_party_type,spt_city),
			(party_set_slot,'p_village_26',slot_party_food,5000),
			(party_set_slot,'p_village_26',slot_party_icon,'icon_village'),
			(party_set_slot,'p_village_26',slot_party_icon_state,tis_normal),
			(party_set_slot,'p_village_26',slot_party_ai_state,null),
			(party_set_slot,'p_village_26',slot_party_ai_object,null),
			(party_set_slot,'p_village_26',slot_town_accumulated_rents,0),
			(party_set_slot,'p_village_26',slot_town_accumulated_tariffs,0),
			(party_set_slot,'p_village_26',slot_town_current_improvement,null),
			(party_set_slot,'p_village_26',slot_town_improvement_end_hour,null),
			(party_set_slot,'p_village_26',slot_town_housing_level,1),
			(party_set_slot,'p_village_26',slot_town_irrigation_level,1),
			(party_set_slot,'p_village_26',slot_town_mill_level,1),
			(party_set_slot,'p_village_26',slot_town_raided_by,null),
			(party_set_slot,'p_village_26',slot_town_state,sts_normal),
			(party_set_slot,'p_village_26',slot_town_raid_progress,null),
			(party_set_slot,'p_village_26',slot_town_recover_progress,null),
			(party_set_slot,'p_village_26',slot_town_production_bonus,1),
			(party_set_slot,'p_village_26',slot_town_siege_days,0),
			(party_set_slot,'p_village_26',slot_town_reserve_patrol,null),
			(party_set_slot,'p_village_26',slot_town_trade_good_productions_begin,null),
			(party_set_slot,'p_village_26',slot_town_trade_good_temp_productions_begin,null),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_village_26',slot_town_trade_good_price_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_village_26',slot_town_trade_good_abundance_array,'$return'),
			(party_set_slot,'p_village_26',slot_town_tax_rate,100),
			(party_set_slot,'p_village_26',slot_town_shoen,null),
			(party_set_slot,'p_village_26',slot_town_prefecture_array,null),
			(party_set_slot,'p_village_26',slot_town_reinforcements_a,'pt_village_reinforcements_a'),
			(party_set_slot,'p_village_26',slot_town_reinforcements_b,'pt_village_reinforcements_b'),
			(party_set_slot,'p_village_26',slot_town_reinforcements_c,'pt_village_reinforcements_c'),
			(party_set_slot,'p_village_26',slot_town_population,1000),
			(party_set_slot,'p_village_26',slot_town_population_max,5000),
			(party_set_slot,'p_village_26',slot_town_population_growth_factor,1),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_26',slot_town_demand_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_26',slot_town_storehouse_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_26',slot_town_facility_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_26',slot_town_surplus_array,'$return'),

			(party_set_slot,'p_village_27',slot_town_center,'scn_village'),
			(party_set_slot,'p_village_27',slot_town_castle,0),
			(party_set_slot,'p_village_27',slot_town_inn,0),
			(party_set_slot,'p_village_27',slot_town_store,0),
			(party_set_slot,'p_village_27',slot_town_smithy,0),
			(party_set_slot,'p_village_27',slot_town_capital,tsuruga),
			(party_set_slot,'p_village_27',slot_town_dojo,0),
			(party_set_slot,'p_village_27',slot_town_sensei,-1),
			(party_set_slot,'p_village_27',slot_town_kokujin,'trp_village_27_kokujin'),
			(party_set_slot,'p_village_27',slot_town_innkeeper,'trp_village_27_innkeeper'),
			(party_set_slot,'p_village_27',slot_town_merchant,'trp_village_27_merchant'),
			(party_set_slot,'p_village_27',slot_town_broker,null),
			(party_set_slot,'p_village_27',slot_town_moneychanger,null),
			(party_set_slot,'p_village_27',slot_town_fishmonger,'trp_village_27_fishmonger'),
			(party_set_slot,'p_village_27',slot_town_horse_trader,null),
			(party_set_slot,'p_village_27',slot_town_export_good,itm_kyoto_sake),
			(party_set_slot,'p_village_27',slot_town_export_rate,100),
			(party_set_slot,'p_village_27',slot_town_import_good,itm_salt),
			(party_set_slot,'p_village_27',slot_town_import_rate,100),
			(party_set_slot,'p_village_27',slot_town_terrain,ter_high_valley),
			(party_set_slot,'p_village_27',slot_town_size,ct_village),
			(party_set_slot,'p_village_27',slot_town_mercs,'p_village_27_mercs'),
			(party_set_slot,'p_village_27',slot_town_trade_hub,0),
			(call_script,'script_town_init_trade_dest','p_village_27',otsu,null,null,null,null,null),
			(party_set_slot,'p_village_27',slot_town_trade_month,4),
			(party_set_slot,'p_village_27',slot_town_att_to_player,att_cautious),
			(party_set_slot,'p_village_27',slot_town_player_relation,0),
			(party_set_slot,'p_village_27',slot_town_import_demand,3),
			(party_set_slot,'p_village_27',slot_town_export_demand,3),
			(party_set_slot,'p_village_27',slot_town_demand,0),
			(party_set_slot,'p_village_27',slot_town_treasury,3600),
			(party_set_slot,'p_village_27',slot_town_garrison_source,'p_village_garrison_source'),
			(party_set_slot,'p_village_27',slot_town_siege_active,0),
			(party_set_slot,'p_village_27',slot_town_under_siege,false),
			(party_set_slot,'p_village_27',slot_town_is_besieged_by,null),
			(party_set_slot,'p_village_27',slot_town_initial_faction,0),
			(party_set_slot,'p_village_27',slot_town_scene_flags,0),
			(party_set_slot,'p_village_27',slot_town_reserve_patrol,-1),
			(party_set_slot,'p_village_27',slot_town_spawn_points,1000),
			(party_set_slot,'p_village_27',slot_party_type,spt_city),
			(party_set_slot,'p_village_27',slot_party_food,5000),
			(party_set_slot,'p_village_27',slot_party_icon,'icon_village'),
			(party_set_slot,'p_village_27',slot_party_icon_state,tis_normal),
			(party_set_slot,'p_village_27',slot_party_ai_state,null),
			(party_set_slot,'p_village_27',slot_party_ai_object,null),
			(party_set_slot,'p_village_27',slot_town_accumulated_rents,0),
			(party_set_slot,'p_village_27',slot_town_accumulated_tariffs,0),
			(party_set_slot,'p_village_27',slot_town_current_improvement,null),
			(party_set_slot,'p_village_27',slot_town_improvement_end_hour,null),
			(party_set_slot,'p_village_27',slot_town_housing_level,1),
			(party_set_slot,'p_village_27',slot_town_irrigation_level,1),
			(party_set_slot,'p_village_27',slot_town_mill_level,1),
			(party_set_slot,'p_village_27',slot_town_raided_by,null),
			(party_set_slot,'p_village_27',slot_town_state,sts_normal),
			(party_set_slot,'p_village_27',slot_town_raid_progress,null),
			(party_set_slot,'p_village_27',slot_town_recover_progress,null),
			(party_set_slot,'p_village_27',slot_town_production_bonus,1),
			(party_set_slot,'p_village_27',slot_town_siege_days,0),
			(party_set_slot,'p_village_27',slot_town_reserve_patrol,null),
			(party_set_slot,'p_village_27',slot_town_trade_good_productions_begin,null),
			(party_set_slot,'p_village_27',slot_town_trade_good_temp_productions_begin,null),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_village_27',slot_town_trade_good_price_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_village_27',slot_town_trade_good_abundance_array,'$return'),
			(party_set_slot,'p_village_27',slot_town_tax_rate,100),
			(party_set_slot,'p_village_27',slot_town_shoen,null),
			(party_set_slot,'p_village_27',slot_town_prefecture_array,null),
			(party_set_slot,'p_village_27',slot_town_reinforcements_a,'pt_village_reinforcements_a'),
			(party_set_slot,'p_village_27',slot_town_reinforcements_b,'pt_village_reinforcements_b'),
			(party_set_slot,'p_village_27',slot_town_reinforcements_c,'pt_village_reinforcements_c'),
			(party_set_slot,'p_village_27',slot_town_population,1000),
			(party_set_slot,'p_village_27',slot_town_population_max,5000),
			(party_set_slot,'p_village_27',slot_town_population_growth_factor,1),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_27',slot_town_demand_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_27',slot_town_storehouse_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_27',slot_town_facility_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_27',slot_town_surplus_array,'$return'),

			(party_set_slot,'p_village_28',slot_town_center,'scn_village'),
			(party_set_slot,'p_village_28',slot_town_castle,0),
			(party_set_slot,'p_village_28',slot_town_inn,0),
			(party_set_slot,'p_village_28',slot_town_store,0),
			(party_set_slot,'p_village_28',slot_town_smithy,0),
			(party_set_slot,'p_village_28',slot_town_capital,miyazu),
			(party_set_slot,'p_village_28',slot_town_dojo,0),
			(party_set_slot,'p_village_28',slot_town_sensei,-1),
			(party_set_slot,'p_village_28',slot_town_kokujin,'trp_village_28_kokujin'),
			(party_set_slot,'p_village_28',slot_town_innkeeper,'trp_village_28_innkeeper'),
			(party_set_slot,'p_village_28',slot_town_merchant,'trp_village_28_merchant'),
			(party_set_slot,'p_village_28',slot_town_broker,null),
			(party_set_slot,'p_village_28',slot_town_moneychanger,null),
			(party_set_slot,'p_village_28',slot_town_fishmonger,'trp_village_28_fishmonger'),
			(party_set_slot,'p_village_28',slot_town_horse_trader,null),
			(party_set_slot,'p_village_28',slot_town_export_good,itm_kyoto_sake),
			(party_set_slot,'p_village_28',slot_town_export_rate,100),
			(party_set_slot,'p_village_28',slot_town_import_good,itm_salt),
			(party_set_slot,'p_village_28',slot_town_import_rate,100),
			(party_set_slot,'p_village_28',slot_town_terrain,ter_seaside),
			(party_set_slot,'p_village_28',slot_town_size,ct_village),
			(party_set_slot,'p_village_28',slot_town_mercs,'p_village_28_mercs'),
			(party_set_slot,'p_village_28',slot_town_trade_hub,0),
			(call_script,'script_town_init_trade_dest','p_village_28',miyazu,null,null,null,null,null),
			(party_set_slot,'p_village_28',slot_town_trade_month,7),
			(party_set_slot,'p_village_28',slot_town_att_to_player,att_cautious),
			(party_set_slot,'p_village_28',slot_town_player_relation,0),
			(party_set_slot,'p_village_28',slot_town_import_demand,3),
			(party_set_slot,'p_village_28',slot_town_export_demand,3),
			(party_set_slot,'p_village_28',slot_town_demand,0),
			(party_set_slot,'p_village_28',slot_town_treasury,3600),
			(party_set_slot,'p_village_28',slot_town_garrison_source,'p_village_garrison_source'),
			(party_set_slot,'p_village_28',slot_town_siege_active,0),
			(party_set_slot,'p_village_28',slot_town_under_siege,false),
			(party_set_slot,'p_village_28',slot_town_is_besieged_by,null),
			(party_set_slot,'p_village_28',slot_town_initial_faction,0),
			(party_set_slot,'p_village_28',slot_town_scene_flags,0),
			(party_set_slot,'p_village_28',slot_town_reserve_patrol,-1),
			(party_set_slot,'p_village_28',slot_town_spawn_points,1000),
			(party_set_slot,'p_village_28',slot_party_type,spt_city),
			(party_set_slot,'p_village_28',slot_party_food,5000),
			(party_set_slot,'p_village_28',slot_party_icon,'icon_village'),
			(party_set_slot,'p_village_28',slot_party_icon_state,tis_normal),
			(party_set_slot,'p_village_28',slot_party_ai_state,null),
			(party_set_slot,'p_village_28',slot_party_ai_object,null),
			(party_set_slot,'p_village_28',slot_town_accumulated_rents,0),
			(party_set_slot,'p_village_28',slot_town_accumulated_tariffs,0),
			(party_set_slot,'p_village_28',slot_town_current_improvement,null),
			(party_set_slot,'p_village_28',slot_town_improvement_end_hour,null),
			(party_set_slot,'p_village_28',slot_town_housing_level,1),
			(party_set_slot,'p_village_28',slot_town_irrigation_level,1),
			(party_set_slot,'p_village_28',slot_town_mill_level,1),
			(party_set_slot,'p_village_28',slot_town_raided_by,null),
			(party_set_slot,'p_village_28',slot_town_state,sts_normal),
			(party_set_slot,'p_village_28',slot_town_raid_progress,null),
			(party_set_slot,'p_village_28',slot_town_recover_progress,null),
			(party_set_slot,'p_village_28',slot_town_production_bonus,1),
			(party_set_slot,'p_village_28',slot_town_siege_days,0),
			(party_set_slot,'p_village_28',slot_town_reserve_patrol,null),
			(party_set_slot,'p_village_28',slot_town_trade_good_productions_begin,null),
			(party_set_slot,'p_village_28',slot_town_trade_good_temp_productions_begin,null),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_village_28',slot_town_trade_good_price_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_village_28',slot_town_trade_good_abundance_array,'$return'),
			(party_set_slot,'p_village_28',slot_town_tax_rate,100),
			(party_set_slot,'p_village_28',slot_town_shoen,null),
			(party_set_slot,'p_village_28',slot_town_prefecture_array,null),
			(party_set_slot,'p_village_28',slot_town_reinforcements_a,'pt_village_reinforcements_a'),
			(party_set_slot,'p_village_28',slot_town_reinforcements_b,'pt_village_reinforcements_b'),
			(party_set_slot,'p_village_28',slot_town_reinforcements_c,'pt_village_reinforcements_c'),
			(party_set_slot,'p_village_28',slot_town_population,1000),
			(party_set_slot,'p_village_28',slot_town_population_max,5000),
			(party_set_slot,'p_village_28',slot_town_population_growth_factor,1),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_28',slot_town_demand_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_28',slot_town_storehouse_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_28',slot_town_facility_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_28',slot_town_surplus_array,'$return'),

			(party_set_slot,'p_village_29',slot_town_center,'scn_village'),
			(party_set_slot,'p_village_29',slot_town_castle,0),
			(party_set_slot,'p_village_29',slot_town_inn,0),
			(party_set_slot,'p_village_29',slot_town_store,0),
			(party_set_slot,'p_village_29',slot_town_smithy,0),
			(party_set_slot,'p_village_29',slot_town_capital,fukuchiyama),
			(party_set_slot,'p_village_29',slot_town_dojo,0),
			(party_set_slot,'p_village_29',slot_town_sensei,-1),
			(party_set_slot,'p_village_29',slot_town_kokujin,'trp_village_29_kokujin'),
			(party_set_slot,'p_village_29',slot_town_innkeeper,'trp_village_29_innkeeper'),
			(party_set_slot,'p_village_29',slot_town_merchant,'trp_village_29_merchant'),
			(party_set_slot,'p_village_29',slot_town_broker,null),
			(party_set_slot,'p_village_29',slot_town_moneychanger,null),
			(party_set_slot,'p_village_29',slot_town_fishmonger,'trp_village_29_fishmonger'),
			(party_set_slot,'p_village_29',slot_town_horse_trader,null),
			(party_set_slot,'p_village_29',slot_town_export_good,itm_kyoto_sake),
			(party_set_slot,'p_village_29',slot_town_export_rate,100),
			(party_set_slot,'p_village_29',slot_town_import_good,itm_salt),
			(party_set_slot,'p_village_29',slot_town_import_rate,100),
			(party_set_slot,'p_village_29',slot_town_terrain,ter_high_valley),
			(party_set_slot,'p_village_29',slot_town_size,ct_village),
			(party_set_slot,'p_village_29',slot_town_mercs,'p_village_29_mercs'),
			(party_set_slot,'p_village_29',slot_town_trade_hub,0),
			(call_script,'script_town_init_trade_dest','p_village_29',fukuchiyama,null,null,null,null,null),
			(party_set_slot,'p_village_29',slot_town_trade_month,10),
			(party_set_slot,'p_village_29',slot_town_att_to_player,att_cautious),
			(party_set_slot,'p_village_29',slot_town_player_relation,0),
			(party_set_slot,'p_village_29',slot_town_import_demand,3),
			(party_set_slot,'p_village_29',slot_town_export_demand,3),
			(party_set_slot,'p_village_29',slot_town_demand,0),
			(party_set_slot,'p_village_29',slot_town_treasury,3600),
			(party_set_slot,'p_village_29',slot_town_garrison_source,'p_village_garrison_source'),
			(party_set_slot,'p_village_29',slot_town_siege_active,0),
			(party_set_slot,'p_village_29',slot_town_under_siege,false),
			(party_set_slot,'p_village_29',slot_town_is_besieged_by,null),
			(party_set_slot,'p_village_29',slot_town_initial_faction,0),
			(party_set_slot,'p_village_29',slot_town_scene_flags,0),
			(party_set_slot,'p_village_29',slot_town_reserve_patrol,-1),
			(party_set_slot,'p_village_29',slot_town_spawn_points,1000),
			(party_set_slot,'p_village_29',slot_party_type,spt_city),
			(party_set_slot,'p_village_29',slot_party_food,5000),
			(party_set_slot,'p_village_29',slot_party_icon,'icon_village'),
			(party_set_slot,'p_village_29',slot_party_icon_state,tis_normal),
			(party_set_slot,'p_village_29',slot_party_ai_state,null),
			(party_set_slot,'p_village_29',slot_party_ai_object,null),
			(party_set_slot,'p_village_29',slot_town_accumulated_rents,0),
			(party_set_slot,'p_village_29',slot_town_accumulated_tariffs,0),
			(party_set_slot,'p_village_29',slot_town_current_improvement,null),
			(party_set_slot,'p_village_29',slot_town_improvement_end_hour,null),
			(party_set_slot,'p_village_29',slot_town_housing_level,1),
			(party_set_slot,'p_village_29',slot_town_irrigation_level,1),
			(party_set_slot,'p_village_29',slot_town_mill_level,1),
			(party_set_slot,'p_village_29',slot_town_raided_by,null),
			(party_set_slot,'p_village_29',slot_town_state,sts_normal),
			(party_set_slot,'p_village_29',slot_town_raid_progress,null),
			(party_set_slot,'p_village_29',slot_town_recover_progress,null),
			(party_set_slot,'p_village_29',slot_town_production_bonus,1),
			(party_set_slot,'p_village_29',slot_town_siege_days,0),
			(party_set_slot,'p_village_29',slot_town_reserve_patrol,null),
			(party_set_slot,'p_village_29',slot_town_trade_good_productions_begin,null),
			(party_set_slot,'p_village_29',slot_town_trade_good_temp_productions_begin,null),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_village_29',slot_town_trade_good_price_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_village_29',slot_town_trade_good_abundance_array,'$return'),
			(party_set_slot,'p_village_29',slot_town_tax_rate,100),
			(party_set_slot,'p_village_29',slot_town_shoen,null),
			(party_set_slot,'p_village_29',slot_town_prefecture_array,null),
			(party_set_slot,'p_village_29',slot_town_reinforcements_a,'pt_village_reinforcements_a'),
			(party_set_slot,'p_village_29',slot_town_reinforcements_b,'pt_village_reinforcements_b'),
			(party_set_slot,'p_village_29',slot_town_reinforcements_c,'pt_village_reinforcements_c'),
			(party_set_slot,'p_village_29',slot_town_population,1000),
			(party_set_slot,'p_village_29',slot_town_population_max,5000),
			(party_set_slot,'p_village_29',slot_town_population_growth_factor,1),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_29',slot_town_demand_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_29',slot_town_storehouse_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_29',slot_town_facility_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_29',slot_town_surplus_array,'$return'),

			(party_set_slot,'p_village_30',slot_town_center,'scn_village'),
			(party_set_slot,'p_village_30',slot_town_castle,0),
			(party_set_slot,'p_village_30',slot_town_inn,0),
			(party_set_slot,'p_village_30',slot_town_store,0),
			(party_set_slot,'p_village_30',slot_town_smithy,0),
			(party_set_slot,'p_village_30',slot_town_capital,fukuchiyama),
			(party_set_slot,'p_village_30',slot_town_dojo,'scn_oe_dojo'),
			(party_set_slot,'p_village_30',slot_town_sensei,'trp_ujiaru'),
			(party_set_slot,'p_village_30',slot_town_kokujin,'trp_village_30_kokujin'),
			(party_set_slot,'p_village_30',slot_town_innkeeper,'trp_village_30_innkeeper'),
			(party_set_slot,'p_village_30',slot_town_merchant,'trp_village_30_merchant'),
			(party_set_slot,'p_village_30',slot_town_broker,null),
			(party_set_slot,'p_village_30',slot_town_moneychanger,null),
			(party_set_slot,'p_village_30',slot_town_fishmonger,'trp_village_30_fishmonger'),
			(party_set_slot,'p_village_30',slot_town_horse_trader,null),
			(party_set_slot,'p_village_30',slot_town_export_good,itm_kyoto_sake),
			(party_set_slot,'p_village_30',slot_town_export_rate,100),
			(party_set_slot,'p_village_30',slot_town_import_good,itm_salt),
			(party_set_slot,'p_village_30',slot_town_import_rate,100),
			(party_set_slot,'p_village_30',slot_town_terrain,ter_high_valley),
			(party_set_slot,'p_village_30',slot_town_size,ct_village),
			(party_set_slot,'p_village_30',slot_town_mercs,'p_village_30_mercs'),
			(party_set_slot,'p_village_30',slot_town_trade_hub,0),
			(call_script,'script_town_init_trade_dest','p_village_30',miyazu,null,null,null,null,null),
			(party_set_slot,'p_village_30',slot_town_trade_month,4),
			(party_set_slot,'p_village_30',slot_town_att_to_player,att_cautious),
			(party_set_slot,'p_village_30',slot_town_player_relation,0),
			(party_set_slot,'p_village_30',slot_town_import_demand,3),
			(party_set_slot,'p_village_30',slot_town_export_demand,3),
			(party_set_slot,'p_village_30',slot_town_demand,0),
			(party_set_slot,'p_village_30',slot_town_treasury,3600),
			(party_set_slot,'p_village_30',slot_town_garrison_source,'p_village_garrison_source'),
			(party_set_slot,'p_village_30',slot_town_siege_active,0),
			(party_set_slot,'p_village_30',slot_town_under_siege,false),
			(party_set_slot,'p_village_30',slot_town_is_besieged_by,null),
			(party_set_slot,'p_village_30',slot_town_initial_faction,0),
			(party_set_slot,'p_village_30',slot_town_scene_flags,0),
			(party_set_slot,'p_village_30',slot_town_reserve_patrol,-1),
			(party_set_slot,'p_village_30',slot_town_spawn_points,1000),
			(party_set_slot,'p_village_30',slot_party_type,spt_city),
			(party_set_slot,'p_village_30',slot_party_food,5000),
			(party_set_slot,'p_village_30',slot_party_icon,'icon_village'),
			(party_set_slot,'p_village_30',slot_party_icon_state,tis_normal),
			(party_set_slot,'p_village_30',slot_party_ai_state,null),
			(party_set_slot,'p_village_30',slot_party_ai_object,null),
			(party_set_slot,'p_village_30',slot_town_accumulated_rents,0),
			(party_set_slot,'p_village_30',slot_town_accumulated_tariffs,0),
			(party_set_slot,'p_village_30',slot_town_current_improvement,null),
			(party_set_slot,'p_village_30',slot_town_improvement_end_hour,null),
			(party_set_slot,'p_village_30',slot_town_housing_level,1),
			(party_set_slot,'p_village_30',slot_town_irrigation_level,1),
			(party_set_slot,'p_village_30',slot_town_mill_level,1),
			(party_set_slot,'p_village_30',slot_town_raided_by,null),
			(party_set_slot,'p_village_30',slot_town_state,sts_normal),
			(party_set_slot,'p_village_30',slot_town_raid_progress,null),
			(party_set_slot,'p_village_30',slot_town_recover_progress,null),
			(party_set_slot,'p_village_30',slot_town_production_bonus,1),
			(party_set_slot,'p_village_30',slot_town_siege_days,0),
			(party_set_slot,'p_village_30',slot_town_reserve_patrol,null),
			(party_set_slot,'p_village_30',slot_town_trade_good_productions_begin,null),
			(party_set_slot,'p_village_30',slot_town_trade_good_temp_productions_begin,null),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_village_30',slot_town_trade_good_price_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_village_30',slot_town_trade_good_abundance_array,'$return'),
			(party_set_slot,'p_village_30',slot_town_tax_rate,100),
			(party_set_slot,'p_village_30',slot_town_shoen,null),
			(party_set_slot,'p_village_30',slot_town_prefecture_array,null),
			(party_set_slot,'p_village_30',slot_town_reinforcements_a,'pt_village_reinforcements_a'),
			(party_set_slot,'p_village_30',slot_town_reinforcements_b,'pt_village_reinforcements_b'),
			(party_set_slot,'p_village_30',slot_town_reinforcements_c,'pt_village_reinforcements_c'),
			(party_set_slot,'p_village_30',slot_town_population,1000),
			(party_set_slot,'p_village_30',slot_town_population_max,5000),
			(party_set_slot,'p_village_30',slot_town_population_growth_factor,1),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_30',slot_town_demand_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_30',slot_town_storehouse_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_30',slot_town_facility_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_30',slot_town_surplus_array,'$return'),

			(party_set_slot,'p_village_31',slot_town_center,'scn_village'),
			(party_set_slot,'p_village_31',slot_town_castle,0),
			(party_set_slot,'p_village_31',slot_town_inn,0),
			(party_set_slot,'p_village_31',slot_town_store,0),
			(party_set_slot,'p_village_31',slot_town_smithy,0),
			(party_set_slot,'p_village_31',slot_town_capital,miyazu),
			(party_set_slot,'p_village_31',slot_town_dojo,0),
			(party_set_slot,'p_village_31',slot_town_sensei,-1),
			(party_set_slot,'p_village_31',slot_town_kokujin,'trp_village_31_kokujin'),
			(party_set_slot,'p_village_31',slot_town_innkeeper,'trp_village_31_innkeeper'),
			(party_set_slot,'p_village_31',slot_town_merchant,'trp_village_31_merchant'),
			(party_set_slot,'p_village_31',slot_town_broker,null),
			(party_set_slot,'p_village_31',slot_town_moneychanger,null),
			(party_set_slot,'p_village_31',slot_town_fishmonger,'trp_village_31_fishmonger'),
			(party_set_slot,'p_village_31',slot_town_horse_trader,null),
			(party_set_slot,'p_village_31',slot_town_export_good,itm_kyoto_sake),
			(party_set_slot,'p_village_31',slot_town_export_rate,100),
			(party_set_slot,'p_village_31',slot_town_import_good,itm_salt),
			(party_set_slot,'p_village_31',slot_town_import_rate,100),
			(party_set_slot,'p_village_31',slot_town_terrain,ter_seaside),
			(party_set_slot,'p_village_31',slot_town_size,ct_large_village),
			(party_set_slot,'p_village_31',slot_town_mercs,'p_village_31_mercs'),
			(party_set_slot,'p_village_31',slot_town_trade_hub,0),
			(call_script,'script_town_init_trade_dest','p_village_31',miyazu,null,null,null,null,null),
			(party_set_slot,'p_village_31',slot_town_trade_month,7),
			(party_set_slot,'p_village_31',slot_town_att_to_player,att_cautious),
			(party_set_slot,'p_village_31',slot_town_player_relation,0),
			(party_set_slot,'p_village_31',slot_town_import_demand,3),
			(party_set_slot,'p_village_31',slot_town_export_demand,3),
			(party_set_slot,'p_village_31',slot_town_demand,0),
			(party_set_slot,'p_village_31',slot_town_treasury,3600),
			(party_set_slot,'p_village_31',slot_town_garrison_source,'p_village_garrison_source'),
			(party_set_slot,'p_village_31',slot_town_siege_active,0),
			(party_set_slot,'p_village_31',slot_town_under_siege,false),
			(party_set_slot,'p_village_31',slot_town_is_besieged_by,null),
			(party_set_slot,'p_village_31',slot_town_initial_faction,0),
			(party_set_slot,'p_village_31',slot_town_scene_flags,0),
			(party_set_slot,'p_village_31',slot_town_reserve_patrol,-1),
			(party_set_slot,'p_village_31',slot_town_spawn_points,1000),
			(party_set_slot,'p_village_31',slot_party_type,spt_city),
			(party_set_slot,'p_village_31',slot_party_food,5000),
			(party_set_slot,'p_village_31',slot_party_icon,'icon_village'),
			(party_set_slot,'p_village_31',slot_party_icon_state,tis_normal),
			(party_set_slot,'p_village_31',slot_party_ai_state,null),
			(party_set_slot,'p_village_31',slot_party_ai_object,null),
			(party_set_slot,'p_village_31',slot_town_accumulated_rents,0),
			(party_set_slot,'p_village_31',slot_town_accumulated_tariffs,0),
			(party_set_slot,'p_village_31',slot_town_current_improvement,null),
			(party_set_slot,'p_village_31',slot_town_improvement_end_hour,null),
			(party_set_slot,'p_village_31',slot_town_housing_level,1),
			(party_set_slot,'p_village_31',slot_town_irrigation_level,1),
			(party_set_slot,'p_village_31',slot_town_mill_level,1),
			(party_set_slot,'p_village_31',slot_town_raided_by,null),
			(party_set_slot,'p_village_31',slot_town_state,sts_normal),
			(party_set_slot,'p_village_31',slot_town_raid_progress,null),
			(party_set_slot,'p_village_31',slot_town_recover_progress,null),
			(party_set_slot,'p_village_31',slot_town_production_bonus,1),
			(party_set_slot,'p_village_31',slot_town_siege_days,0),
			(party_set_slot,'p_village_31',slot_town_reserve_patrol,null),
			(party_set_slot,'p_village_31',slot_town_trade_good_productions_begin,null),
			(party_set_slot,'p_village_31',slot_town_trade_good_temp_productions_begin,null),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_village_31',slot_town_trade_good_price_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_village_31',slot_town_trade_good_abundance_array,'$return'),
			(party_set_slot,'p_village_31',slot_town_tax_rate,100),
			(party_set_slot,'p_village_31',slot_town_shoen,null),
			(party_set_slot,'p_village_31',slot_town_prefecture_array,null),
			(party_set_slot,'p_village_31',slot_town_reinforcements_a,'pt_village_reinforcements_a'),
			(party_set_slot,'p_village_31',slot_town_reinforcements_b,'pt_village_reinforcements_b'),
			(party_set_slot,'p_village_31',slot_town_reinforcements_c,'pt_village_reinforcements_c'),
			(party_set_slot,'p_village_31',slot_town_population,1000),
			(party_set_slot,'p_village_31',slot_town_population_max,5000),
			(party_set_slot,'p_village_31',slot_town_population_growth_factor,1),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_31',slot_town_demand_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_31',slot_town_storehouse_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_31',slot_town_facility_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_31',slot_town_surplus_array,'$return'),

			(party_set_slot,'p_village_32',slot_town_center,'scn_village'),
			(party_set_slot,'p_village_32',slot_town_castle,0),
			(party_set_slot,'p_village_32',slot_town_inn,0),
			(party_set_slot,'p_village_32',slot_town_store,0),
			(party_set_slot,'p_village_32',slot_town_smithy,0),
			(party_set_slot,'p_village_32',slot_town_capital,miyazu),
			(party_set_slot,'p_village_32',slot_town_dojo,0),
			(party_set_slot,'p_village_32',slot_town_sensei,-1),
			(party_set_slot,'p_village_32',slot_town_kokujin,'trp_village_32_kokujin'),
			(party_set_slot,'p_village_32',slot_town_innkeeper,'trp_village_32_innkeeper'),
			(party_set_slot,'p_village_32',slot_town_merchant,'trp_village_32_merchant'),
			(party_set_slot,'p_village_32',slot_town_broker,null),
			(party_set_slot,'p_village_32',slot_town_moneychanger,null),
			(party_set_slot,'p_village_32',slot_town_fishmonger,'trp_village_32_fishmonger'),
			(party_set_slot,'p_village_32',slot_town_horse_trader,null),
			(party_set_slot,'p_village_32',slot_town_export_good,itm_kyoto_sake),
			(party_set_slot,'p_village_32',slot_town_export_rate,100),
			(party_set_slot,'p_village_32',slot_town_import_good,itm_salt),
			(party_set_slot,'p_village_32',slot_town_import_rate,100),
			(party_set_slot,'p_village_32',slot_town_terrain,ter_seaside),
			(party_set_slot,'p_village_32',slot_town_size,ct_small_village),
			(party_set_slot,'p_village_32',slot_town_mercs,'p_village_32_mercs'),
			(party_set_slot,'p_village_32',slot_town_trade_hub,0),
			(call_script,'script_town_init_trade_dest','p_village_32',miyazu,null,null,null,null,null),
			(party_set_slot,'p_village_32',slot_town_trade_month,10),
			(party_set_slot,'p_village_32',slot_town_att_to_player,att_cautious),
			(party_set_slot,'p_village_32',slot_town_player_relation,0),
			(party_set_slot,'p_village_32',slot_town_import_demand,3),
			(party_set_slot,'p_village_32',slot_town_export_demand,3),
			(party_set_slot,'p_village_32',slot_town_demand,0),
			(party_set_slot,'p_village_32',slot_town_treasury,3600),
			(party_set_slot,'p_village_32',slot_town_garrison_source,'p_village_garrison_source'),
			(party_set_slot,'p_village_32',slot_town_siege_active,0),
			(party_set_slot,'p_village_32',slot_town_under_siege,false),
			(party_set_slot,'p_village_32',slot_town_is_besieged_by,null),
			(party_set_slot,'p_village_32',slot_town_initial_faction,0),
			(party_set_slot,'p_village_32',slot_town_scene_flags,0),
			(party_set_slot,'p_village_32',slot_town_reserve_patrol,-1),
			(party_set_slot,'p_village_32',slot_town_spawn_points,1000),
			(party_set_slot,'p_village_32',slot_party_type,spt_city),
			(party_set_slot,'p_village_32',slot_party_food,5000),
			(party_set_slot,'p_village_32',slot_party_icon,'icon_village'),
			(party_set_slot,'p_village_32',slot_party_icon_state,tis_normal),
			(party_set_slot,'p_village_32',slot_party_ai_state,null),
			(party_set_slot,'p_village_32',slot_party_ai_object,null),
			(party_set_slot,'p_village_32',slot_town_accumulated_rents,0),
			(party_set_slot,'p_village_32',slot_town_accumulated_tariffs,0),
			(party_set_slot,'p_village_32',slot_town_current_improvement,null),
			(party_set_slot,'p_village_32',slot_town_improvement_end_hour,null),
			(party_set_slot,'p_village_32',slot_town_housing_level,1),
			(party_set_slot,'p_village_32',slot_town_irrigation_level,1),
			(party_set_slot,'p_village_32',slot_town_mill_level,1),
			(party_set_slot,'p_village_32',slot_town_raided_by,null),
			(party_set_slot,'p_village_32',slot_town_state,sts_normal),
			(party_set_slot,'p_village_32',slot_town_raid_progress,null),
			(party_set_slot,'p_village_32',slot_town_recover_progress,null),
			(party_set_slot,'p_village_32',slot_town_production_bonus,1),
			(party_set_slot,'p_village_32',slot_town_siege_days,0),
			(party_set_slot,'p_village_32',slot_town_reserve_patrol,null),
			(party_set_slot,'p_village_32',slot_town_trade_good_productions_begin,null),
			(party_set_slot,'p_village_32',slot_town_trade_good_temp_productions_begin,null),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_village_32',slot_town_trade_good_price_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_village_32',slot_town_trade_good_abundance_array,'$return'),
			(party_set_slot,'p_village_32',slot_town_tax_rate,100),
			(party_set_slot,'p_village_32',slot_town_shoen,null),
			(party_set_slot,'p_village_32',slot_town_prefecture_array,null),
			(party_set_slot,'p_village_32',slot_town_reinforcements_a,'pt_village_reinforcements_a'),
			(party_set_slot,'p_village_32',slot_town_reinforcements_b,'pt_village_reinforcements_b'),
			(party_set_slot,'p_village_32',slot_town_reinforcements_c,'pt_village_reinforcements_c'),
			(party_set_slot,'p_village_32',slot_town_population,1000),
			(party_set_slot,'p_village_32',slot_town_population_max,5000),
			(party_set_slot,'p_village_32',slot_town_population_growth_factor,1),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_32',slot_town_demand_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_32',slot_town_storehouse_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_32',slot_town_facility_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_32',slot_town_surplus_array,'$return'),

			(party_set_slot,'p_village_33',slot_town_center,'scn_village'),
			(party_set_slot,'p_village_33',slot_town_castle,0),
			(party_set_slot,'p_village_33',slot_town_inn,0),
			(party_set_slot,'p_village_33',slot_town_store,0),
			(party_set_slot,'p_village_33',slot_town_smithy,0),
			(party_set_slot,'p_village_33',slot_town_capital,nara),
			(party_set_slot,'p_village_33',slot_town_dojo,0),
			(party_set_slot,'p_village_33',slot_town_sensei,-1),
			(party_set_slot,'p_village_33',slot_town_kokujin,'trp_village_33_kokujin'),
			(party_set_slot,'p_village_33',slot_town_innkeeper,'trp_village_33_innkeeper'),
			(party_set_slot,'p_village_33',slot_town_merchant,'trp_village_33_merchant'),
			(party_set_slot,'p_village_33',slot_town_broker,null),
			(party_set_slot,'p_village_33',slot_town_moneychanger,null),
			(party_set_slot,'p_village_33',slot_town_fishmonger,'trp_village_33_fishmonger'),
			(party_set_slot,'p_village_33',slot_town_horse_trader,null),
			(party_set_slot,'p_village_33',slot_town_export_good,itm_kyoto_sake),
			(party_set_slot,'p_village_33',slot_town_export_rate,100),
			(party_set_slot,'p_village_33',slot_town_import_good,itm_salt),
			(party_set_slot,'p_village_33',slot_town_import_rate,100),
			(party_set_slot,'p_village_33',slot_town_terrain,ter_highland),
			(party_set_slot,'p_village_33',slot_town_size,ct_village),
			(party_set_slot,'p_village_33',slot_town_mercs,'p_village_33_mercs'),
			(party_set_slot,'p_village_33',slot_town_trade_hub,0),
			(call_script,'script_town_init_trade_dest','p_village_33',nabari,null,null,null,null,null),
			(party_set_slot,'p_village_33',slot_town_trade_month,4),
			(party_set_slot,'p_village_33',slot_town_att_to_player,att_cautious),
			(party_set_slot,'p_village_33',slot_town_player_relation,0),
			(party_set_slot,'p_village_33',slot_town_import_demand,3),
			(party_set_slot,'p_village_33',slot_town_export_demand,3),
			(party_set_slot,'p_village_33',slot_town_demand,0),
			(party_set_slot,'p_village_33',slot_town_treasury,3600),
			(party_set_slot,'p_village_33',slot_town_garrison_source,'p_village_garrison_source'),
			(party_set_slot,'p_village_33',slot_town_siege_active,0),
			(party_set_slot,'p_village_33',slot_town_under_siege,false),
			(party_set_slot,'p_village_33',slot_town_is_besieged_by,null),
			(party_set_slot,'p_village_33',slot_town_initial_faction,0),
			(party_set_slot,'p_village_33',slot_town_scene_flags,0),
			(party_set_slot,'p_village_33',slot_town_reserve_patrol,-1),
			(party_set_slot,'p_village_33',slot_town_spawn_points,1000),
			(party_set_slot,'p_village_33',slot_party_type,spt_city),
			(party_set_slot,'p_village_33',slot_party_food,5000),
			(party_set_slot,'p_village_33',slot_party_icon,'icon_village'),
			(party_set_slot,'p_village_33',slot_party_icon_state,tis_normal),
			(party_set_slot,'p_village_33',slot_party_ai_state,null),
			(party_set_slot,'p_village_33',slot_party_ai_object,null),
			(party_set_slot,'p_village_33',slot_town_accumulated_rents,0),
			(party_set_slot,'p_village_33',slot_town_accumulated_tariffs,0),
			(party_set_slot,'p_village_33',slot_town_current_improvement,null),
			(party_set_slot,'p_village_33',slot_town_improvement_end_hour,null),
			(party_set_slot,'p_village_33',slot_town_housing_level,1),
			(party_set_slot,'p_village_33',slot_town_irrigation_level,1),
			(party_set_slot,'p_village_33',slot_town_mill_level,1),
			(party_set_slot,'p_village_33',slot_town_raided_by,null),
			(party_set_slot,'p_village_33',slot_town_state,sts_normal),
			(party_set_slot,'p_village_33',slot_town_raid_progress,null),
			(party_set_slot,'p_village_33',slot_town_recover_progress,null),
			(party_set_slot,'p_village_33',slot_town_production_bonus,1),
			(party_set_slot,'p_village_33',slot_town_siege_days,0),
			(party_set_slot,'p_village_33',slot_town_reserve_patrol,null),
			(party_set_slot,'p_village_33',slot_town_trade_good_productions_begin,null),
			(party_set_slot,'p_village_33',slot_town_trade_good_temp_productions_begin,null),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_village_33',slot_town_trade_good_price_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_village_33',slot_town_trade_good_abundance_array,'$return'),
			(party_set_slot,'p_village_33',slot_town_tax_rate,100),
			(party_set_slot,'p_village_33',slot_town_shoen,null),
			(party_set_slot,'p_village_33',slot_town_prefecture_array,null),
			(party_set_slot,'p_village_33',slot_town_reinforcements_a,'pt_village_reinforcements_a'),
			(party_set_slot,'p_village_33',slot_town_reinforcements_b,'pt_village_reinforcements_b'),
			(party_set_slot,'p_village_33',slot_town_reinforcements_c,'pt_village_reinforcements_c'),
			(party_set_slot,'p_village_33',slot_town_population,1000),
			(party_set_slot,'p_village_33',slot_town_population_max,5000),
			(party_set_slot,'p_village_33',slot_town_population_growth_factor,1),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_33',slot_town_demand_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_33',slot_town_storehouse_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_33',slot_town_facility_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_33',slot_town_surplus_array,'$return'),

			(party_set_slot,'p_village_34',slot_town_center,'scn_village'),
			(party_set_slot,'p_village_34',slot_town_castle,0),
			(party_set_slot,'p_village_34',slot_town_inn,0),
			(party_set_slot,'p_village_34',slot_town_store,0),
			(party_set_slot,'p_village_34',slot_town_smithy,0),
			(party_set_slot,'p_village_34',slot_town_capital,wakayama),
			(party_set_slot,'p_village_34',slot_town_dojo,0),
			(party_set_slot,'p_village_34',slot_town_sensei,-1),
			(party_set_slot,'p_village_34',slot_town_kokujin,'trp_village_34_kokujin'),
			(party_set_slot,'p_village_34',slot_town_innkeeper,'trp_village_34_innkeeper'),
			(party_set_slot,'p_village_34',slot_town_merchant,'trp_village_34_merchant'),
			(party_set_slot,'p_village_34',slot_town_broker,null),
			(party_set_slot,'p_village_34',slot_town_moneychanger,null),
			(party_set_slot,'p_village_34',slot_town_fishmonger,'trp_village_34_fishmonger'),
			(party_set_slot,'p_village_34',slot_town_horse_trader,null),
			(party_set_slot,'p_village_34',slot_town_export_good,itm_kyoto_sake),
			(party_set_slot,'p_village_34',slot_town_export_rate,100),
			(party_set_slot,'p_village_34',slot_town_import_good,itm_salt),
			(party_set_slot,'p_village_34',slot_town_import_rate,100),
			(party_set_slot,'p_village_34',slot_town_terrain,ter_highland),
			(party_set_slot,'p_village_34',slot_town_size,ct_village),
			(party_set_slot,'p_village_34',slot_town_mercs,'p_village_34_mercs'),
			(party_set_slot,'p_village_34',slot_town_trade_hub,0),
			(call_script,'script_town_init_trade_dest','p_village_34',nara,null,null,null,null,null),
			(party_set_slot,'p_village_34',slot_town_trade_month,7),
			(party_set_slot,'p_village_34',slot_town_att_to_player,att_cautious),
			(party_set_slot,'p_village_34',slot_town_player_relation,0),
			(party_set_slot,'p_village_34',slot_town_import_demand,3),
			(party_set_slot,'p_village_34',slot_town_export_demand,3),
			(party_set_slot,'p_village_34',slot_town_demand,0),
			(party_set_slot,'p_village_34',slot_town_treasury,3600),
			(party_set_slot,'p_village_34',slot_town_garrison_source,'p_village_garrison_source'),
			(party_set_slot,'p_village_34',slot_town_siege_active,0),
			(party_set_slot,'p_village_34',slot_town_under_siege,false),
			(party_set_slot,'p_village_34',slot_town_is_besieged_by,null),
			(party_set_slot,'p_village_34',slot_town_initial_faction,0),
			(party_set_slot,'p_village_34',slot_town_scene_flags,0),
			(party_set_slot,'p_village_34',slot_town_reserve_patrol,-1),
			(party_set_slot,'p_village_34',slot_town_spawn_points,1000),
			(party_set_slot,'p_village_34',slot_party_type,spt_city),
			(party_set_slot,'p_village_34',slot_party_food,5000),
			(party_set_slot,'p_village_34',slot_party_icon,'icon_village'),
			(party_set_slot,'p_village_34',slot_party_icon_state,tis_normal),
			(party_set_slot,'p_village_34',slot_party_ai_state,null),
			(party_set_slot,'p_village_34',slot_party_ai_object,null),
			(party_set_slot,'p_village_34',slot_town_accumulated_rents,0),
			(party_set_slot,'p_village_34',slot_town_accumulated_tariffs,0),
			(party_set_slot,'p_village_34',slot_town_current_improvement,null),
			(party_set_slot,'p_village_34',slot_town_improvement_end_hour,null),
			(party_set_slot,'p_village_34',slot_town_housing_level,1),
			(party_set_slot,'p_village_34',slot_town_irrigation_level,1),
			(party_set_slot,'p_village_34',slot_town_mill_level,1),
			(party_set_slot,'p_village_34',slot_town_raided_by,null),
			(party_set_slot,'p_village_34',slot_town_state,sts_normal),
			(party_set_slot,'p_village_34',slot_town_raid_progress,null),
			(party_set_slot,'p_village_34',slot_town_recover_progress,null),
			(party_set_slot,'p_village_34',slot_town_production_bonus,1),
			(party_set_slot,'p_village_34',slot_town_siege_days,0),
			(party_set_slot,'p_village_34',slot_town_reserve_patrol,null),
			(party_set_slot,'p_village_34',slot_town_trade_good_productions_begin,null),
			(party_set_slot,'p_village_34',slot_town_trade_good_temp_productions_begin,null),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_village_34',slot_town_trade_good_price_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_village_34',slot_town_trade_good_abundance_array,'$return'),
			(party_set_slot,'p_village_34',slot_town_tax_rate,100),
			(party_set_slot,'p_village_34',slot_town_shoen,null),
			(party_set_slot,'p_village_34',slot_town_prefecture_array,null),
			(party_set_slot,'p_village_34',slot_town_reinforcements_a,'pt_village_reinforcements_a'),
			(party_set_slot,'p_village_34',slot_town_reinforcements_b,'pt_village_reinforcements_b'),
			(party_set_slot,'p_village_34',slot_town_reinforcements_c,'pt_village_reinforcements_c'),
			(party_set_slot,'p_village_34',slot_town_population,1000),
			(party_set_slot,'p_village_34',slot_town_population_max,5000),
			(party_set_slot,'p_village_34',slot_town_population_growth_factor,1),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_34',slot_town_demand_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_34',slot_town_storehouse_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_34',slot_town_facility_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_34',slot_town_surplus_array,'$return'),

			(party_set_slot,'p_village_35',slot_town_center,'scn_village'),
			(party_set_slot,'p_village_35',slot_town_castle,0),
			(party_set_slot,'p_village_35',slot_town_inn,0),
			(party_set_slot,'p_village_35',slot_town_store,0),
			(party_set_slot,'p_village_35',slot_town_smithy,0),
			(party_set_slot,'p_village_35',slot_town_capital,nara),
			(party_set_slot,'p_village_35',slot_town_dojo,0),
			(party_set_slot,'p_village_35',slot_town_sensei,-1),
			(party_set_slot,'p_village_35',slot_town_kokujin,'trp_village_35_kokujin'),
			(party_set_slot,'p_village_35',slot_town_innkeeper,'trp_village_35_innkeeper'),
			(party_set_slot,'p_village_35',slot_town_merchant,'trp_village_35_merchant'),
			(party_set_slot,'p_village_35',slot_town_broker,null),
			(party_set_slot,'p_village_35',slot_town_moneychanger,null),
			(party_set_slot,'p_village_35',slot_town_fishmonger,'trp_village_35_fishmonger'),
			(party_set_slot,'p_village_35',slot_town_horse_trader,null),
			(party_set_slot,'p_village_35',slot_town_export_good,itm_kyoto_sake),
			(party_set_slot,'p_village_35',slot_town_export_rate,100),
			(party_set_slot,'p_village_35',slot_town_import_good,itm_salt),
			(party_set_slot,'p_village_35',slot_town_import_rate,100),
			(party_set_slot,'p_village_35',slot_town_terrain,ter_low_valley),
			(party_set_slot,'p_village_35',slot_town_size,ct_village),
			(party_set_slot,'p_village_35',slot_town_mercs,'p_village_35_mercs'),
			(party_set_slot,'p_village_35',slot_town_trade_hub,0),
			(call_script,'script_town_init_trade_dest','p_village_35',fujidera,null,null,null,null,null),
			(party_set_slot,'p_village_35',slot_town_trade_month,10),
			(party_set_slot,'p_village_35',slot_town_att_to_player,att_cautious),
			(party_set_slot,'p_village_35',slot_town_player_relation,0),
			(party_set_slot,'p_village_35',slot_town_import_demand,3),
			(party_set_slot,'p_village_35',slot_town_export_demand,3),
			(party_set_slot,'p_village_35',slot_town_demand,0),
			(party_set_slot,'p_village_35',slot_town_treasury,3600),
			(party_set_slot,'p_village_35',slot_town_garrison_source,'p_village_garrison_source'),
			(party_set_slot,'p_village_35',slot_town_siege_active,0),
			(party_set_slot,'p_village_35',slot_town_under_siege,false),
			(party_set_slot,'p_village_35',slot_town_is_besieged_by,null),
			(party_set_slot,'p_village_35',slot_town_initial_faction,0),
			(party_set_slot,'p_village_35',slot_town_scene_flags,0),
			(party_set_slot,'p_village_35',slot_town_reserve_patrol,-1),
			(party_set_slot,'p_village_35',slot_town_spawn_points,1000),
			(party_set_slot,'p_village_35',slot_party_type,spt_city),
			(party_set_slot,'p_village_35',slot_party_food,5000),
			(party_set_slot,'p_village_35',slot_party_icon,'icon_village'),
			(party_set_slot,'p_village_35',slot_party_icon_state,tis_normal),
			(party_set_slot,'p_village_35',slot_party_ai_state,null),
			(party_set_slot,'p_village_35',slot_party_ai_object,null),
			(party_set_slot,'p_village_35',slot_town_accumulated_rents,0),
			(party_set_slot,'p_village_35',slot_town_accumulated_tariffs,0),
			(party_set_slot,'p_village_35',slot_town_current_improvement,null),
			(party_set_slot,'p_village_35',slot_town_improvement_end_hour,null),
			(party_set_slot,'p_village_35',slot_town_housing_level,1),
			(party_set_slot,'p_village_35',slot_town_irrigation_level,1),
			(party_set_slot,'p_village_35',slot_town_mill_level,1),
			(party_set_slot,'p_village_35',slot_town_raided_by,null),
			(party_set_slot,'p_village_35',slot_town_state,sts_normal),
			(party_set_slot,'p_village_35',slot_town_raid_progress,null),
			(party_set_slot,'p_village_35',slot_town_recover_progress,null),
			(party_set_slot,'p_village_35',slot_town_production_bonus,1),
			(party_set_slot,'p_village_35',slot_town_siege_days,0),
			(party_set_slot,'p_village_35',slot_town_reserve_patrol,null),
			(party_set_slot,'p_village_35',slot_town_trade_good_productions_begin,null),
			(party_set_slot,'p_village_35',slot_town_trade_good_temp_productions_begin,null),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_village_35',slot_town_trade_good_price_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_village_35',slot_town_trade_good_abundance_array,'$return'),
			(party_set_slot,'p_village_35',slot_town_tax_rate,100),
			(party_set_slot,'p_village_35',slot_town_shoen,null),
			(party_set_slot,'p_village_35',slot_town_prefecture_array,null),
			(party_set_slot,'p_village_35',slot_town_reinforcements_a,'pt_village_reinforcements_a'),
			(party_set_slot,'p_village_35',slot_town_reinforcements_b,'pt_village_reinforcements_b'),
			(party_set_slot,'p_village_35',slot_town_reinforcements_c,'pt_village_reinforcements_c'),
			(party_set_slot,'p_village_35',slot_town_population,1000),
			(party_set_slot,'p_village_35',slot_town_population_max,5000),
			(party_set_slot,'p_village_35',slot_town_population_growth_factor,1),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_35',slot_town_demand_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_35',slot_town_storehouse_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_35',slot_town_facility_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_35',slot_town_surplus_array,'$return'),

			(party_set_slot,'p_village_36',slot_town_center,'scn_village'),
			(party_set_slot,'p_village_36',slot_town_castle,0),
			(party_set_slot,'p_village_36',slot_town_inn,0),
			(party_set_slot,'p_village_36',slot_town_store,0),
			(party_set_slot,'p_village_36',slot_town_smithy,0),
			(party_set_slot,'p_village_36',slot_town_capital,wakayama),
			(party_set_slot,'p_village_36',slot_town_dojo,0),
			(party_set_slot,'p_village_36',slot_town_sensei,-1),
			(party_set_slot,'p_village_36',slot_town_kokujin,'trp_village_36_kokujin'),
			(party_set_slot,'p_village_36',slot_town_innkeeper,'trp_village_36_innkeeper'),
			(party_set_slot,'p_village_36',slot_town_merchant,'trp_village_36_merchant'),
			(party_set_slot,'p_village_36',slot_town_broker,null),
			(party_set_slot,'p_village_36',slot_town_moneychanger,null),
			(party_set_slot,'p_village_36',slot_town_fishmonger,'trp_village_36_fishmonger'),
			(party_set_slot,'p_village_36',slot_town_horse_trader,null),
			(party_set_slot,'p_village_36',slot_town_export_good,itm_kyoto_sake),
			(party_set_slot,'p_village_36',slot_town_export_rate,100),
			(party_set_slot,'p_village_36',slot_town_import_good,itm_salt),
			(party_set_slot,'p_village_36',slot_town_import_rate,100),
			(party_set_slot,'p_village_36',slot_town_terrain,ter_highland),
			(party_set_slot,'p_village_36',slot_town_size,ct_village),
			(party_set_slot,'p_village_36',slot_town_mercs,'p_village_36_mercs'),
			(party_set_slot,'p_village_36',slot_town_trade_hub,0),
			(call_script,'script_town_init_trade_dest','p_village_36',nara,null,null,null,null,null),
			(party_set_slot,'p_village_36',slot_town_trade_month,4),
			(party_set_slot,'p_village_36',slot_town_att_to_player,att_cautious),
			(party_set_slot,'p_village_36',slot_town_player_relation,0),
			(party_set_slot,'p_village_36',slot_town_import_demand,3),
			(party_set_slot,'p_village_36',slot_town_export_demand,3),
			(party_set_slot,'p_village_36',slot_town_demand,0),
			(party_set_slot,'p_village_36',slot_town_treasury,3600),
			(party_set_slot,'p_village_36',slot_town_garrison_source,'p_village_garrison_source'),
			(party_set_slot,'p_village_36',slot_town_siege_active,0),
			(party_set_slot,'p_village_36',slot_town_under_siege,false),
			(party_set_slot,'p_village_36',slot_town_is_besieged_by,null),
			(party_set_slot,'p_village_36',slot_town_initial_faction,0),
			(party_set_slot,'p_village_36',slot_town_scene_flags,0),
			(party_set_slot,'p_village_36',slot_town_reserve_patrol,-1),
			(party_set_slot,'p_village_36',slot_town_spawn_points,1000),
			(party_set_slot,'p_village_36',slot_party_type,spt_city),
			(party_set_slot,'p_village_36',slot_party_food,5000),
			(party_set_slot,'p_village_36',slot_party_icon,'icon_village'),
			(party_set_slot,'p_village_36',slot_party_icon_state,tis_normal),
			(party_set_slot,'p_village_36',slot_party_ai_state,null),
			(party_set_slot,'p_village_36',slot_party_ai_object,null),
			(party_set_slot,'p_village_36',slot_town_accumulated_rents,0),
			(party_set_slot,'p_village_36',slot_town_accumulated_tariffs,0),
			(party_set_slot,'p_village_36',slot_town_current_improvement,null),
			(party_set_slot,'p_village_36',slot_town_improvement_end_hour,null),
			(party_set_slot,'p_village_36',slot_town_housing_level,1),
			(party_set_slot,'p_village_36',slot_town_irrigation_level,1),
			(party_set_slot,'p_village_36',slot_town_mill_level,1),
			(party_set_slot,'p_village_36',slot_town_raided_by,null),
			(party_set_slot,'p_village_36',slot_town_state,sts_normal),
			(party_set_slot,'p_village_36',slot_town_raid_progress,null),
			(party_set_slot,'p_village_36',slot_town_recover_progress,null),
			(party_set_slot,'p_village_36',slot_town_production_bonus,1),
			(party_set_slot,'p_village_36',slot_town_siege_days,0),
			(party_set_slot,'p_village_36',slot_town_reserve_patrol,null),
			(party_set_slot,'p_village_36',slot_town_trade_good_productions_begin,null),
			(party_set_slot,'p_village_36',slot_town_trade_good_temp_productions_begin,null),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_village_36',slot_town_trade_good_price_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_village_36',slot_town_trade_good_abundance_array,'$return'),
			(party_set_slot,'p_village_36',slot_town_tax_rate,100),
			(party_set_slot,'p_village_36',slot_town_shoen,null),
			(party_set_slot,'p_village_36',slot_town_prefecture_array,null),
			(party_set_slot,'p_village_36',slot_town_reinforcements_a,'pt_village_reinforcements_a'),
			(party_set_slot,'p_village_36',slot_town_reinforcements_b,'pt_village_reinforcements_b'),
			(party_set_slot,'p_village_36',slot_town_reinforcements_c,'pt_village_reinforcements_c'),
			(party_set_slot,'p_village_36',slot_town_population,1000),
			(party_set_slot,'p_village_36',slot_town_population_max,5000),
			(party_set_slot,'p_village_36',slot_town_population_growth_factor,1),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_36',slot_town_demand_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_36',slot_town_storehouse_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_36',slot_town_facility_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_36',slot_town_surplus_array,'$return'),

			(party_set_slot,'p_village_37',slot_town_center,'scn_village'),
			(party_set_slot,'p_village_37',slot_town_castle,0),
			(party_set_slot,'p_village_37',slot_town_inn,0),
			(party_set_slot,'p_village_37',slot_town_store,0),
			(party_set_slot,'p_village_37',slot_town_smithy,0),
			(party_set_slot,'p_village_37',slot_town_capital,nara),
			(party_set_slot,'p_village_37',slot_town_dojo,0),
			(party_set_slot,'p_village_37',slot_town_sensei,-1),
			(party_set_slot,'p_village_37',slot_town_kokujin,'trp_village_37_kokujin'),
			(party_set_slot,'p_village_37',slot_town_innkeeper,'trp_village_37_innkeeper'),
			(party_set_slot,'p_village_37',slot_town_merchant,'trp_village_37_merchant'),
			(party_set_slot,'p_village_37',slot_town_broker,null),
			(party_set_slot,'p_village_37',slot_town_moneychanger,null),
			(party_set_slot,'p_village_37',slot_town_fishmonger,'trp_village_37_fishmonger'),
			(party_set_slot,'p_village_37',slot_town_horse_trader,null),
			(party_set_slot,'p_village_37',slot_town_export_good,itm_kyoto_sake),
			(party_set_slot,'p_village_37',slot_town_export_rate,100),
			(party_set_slot,'p_village_37',slot_town_import_good,itm_salt),
			(party_set_slot,'p_village_37',slot_town_import_rate,100),
			(party_set_slot,'p_village_37',slot_town_terrain,ter_highland),
			(party_set_slot,'p_village_37',slot_town_size,ct_small_village),
			(party_set_slot,'p_village_37',slot_town_mercs,'p_village_37_mercs'),
			(party_set_slot,'p_village_37',slot_town_trade_hub,0),
			(call_script,'script_town_init_trade_dest','p_village_37',nara,null,null,null,null,null),
			(party_set_slot,'p_village_37',slot_town_trade_month,7),
			(party_set_slot,'p_village_37',slot_town_att_to_player,att_cautious),
			(party_set_slot,'p_village_37',slot_town_player_relation,0),
			(party_set_slot,'p_village_37',slot_town_import_demand,3),
			(party_set_slot,'p_village_37',slot_town_export_demand,3),
			(party_set_slot,'p_village_37',slot_town_demand,0),
			(party_set_slot,'p_village_37',slot_town_treasury,3600),
			(party_set_slot,'p_village_37',slot_town_garrison_source,'p_village_garrison_source'),
			(party_set_slot,'p_village_37',slot_town_siege_active,0),
			(party_set_slot,'p_village_37',slot_town_under_siege,false),
			(party_set_slot,'p_village_37',slot_town_is_besieged_by,null),
			(party_set_slot,'p_village_37',slot_town_initial_faction,0),
			(party_set_slot,'p_village_37',slot_town_scene_flags,0),
			(party_set_slot,'p_village_37',slot_town_reserve_patrol,-1),
			(party_set_slot,'p_village_37',slot_town_spawn_points,1000),
			(party_set_slot,'p_village_37',slot_party_type,spt_city),
			(party_set_slot,'p_village_37',slot_party_food,5000),
			(party_set_slot,'p_village_37',slot_party_icon,'icon_village'),
			(party_set_slot,'p_village_37',slot_party_icon_state,tis_normal),
			(party_set_slot,'p_village_37',slot_party_ai_state,null),
			(party_set_slot,'p_village_37',slot_party_ai_object,null),
			(party_set_slot,'p_village_37',slot_town_accumulated_rents,0),
			(party_set_slot,'p_village_37',slot_town_accumulated_tariffs,0),
			(party_set_slot,'p_village_37',slot_town_current_improvement,null),
			(party_set_slot,'p_village_37',slot_town_improvement_end_hour,null),
			(party_set_slot,'p_village_37',slot_town_housing_level,1),
			(party_set_slot,'p_village_37',slot_town_irrigation_level,1),
			(party_set_slot,'p_village_37',slot_town_mill_level,1),
			(party_set_slot,'p_village_37',slot_town_raided_by,null),
			(party_set_slot,'p_village_37',slot_town_state,sts_normal),
			(party_set_slot,'p_village_37',slot_town_raid_progress,null),
			(party_set_slot,'p_village_37',slot_town_recover_progress,null),
			(party_set_slot,'p_village_37',slot_town_production_bonus,1),
			(party_set_slot,'p_village_37',slot_town_siege_days,0),
			(party_set_slot,'p_village_37',slot_town_reserve_patrol,null),
			(party_set_slot,'p_village_37',slot_town_trade_good_productions_begin,null),
			(party_set_slot,'p_village_37',slot_town_trade_good_temp_productions_begin,null),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_village_37',slot_town_trade_good_price_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_village_37',slot_town_trade_good_abundance_array,'$return'),
			(party_set_slot,'p_village_37',slot_town_tax_rate,100),
			(party_set_slot,'p_village_37',slot_town_shoen,null),
			(party_set_slot,'p_village_37',slot_town_prefecture_array,null),
			(party_set_slot,'p_village_37',slot_town_reinforcements_a,'pt_village_reinforcements_a'),
			(party_set_slot,'p_village_37',slot_town_reinforcements_b,'pt_village_reinforcements_b'),
			(party_set_slot,'p_village_37',slot_town_reinforcements_c,'pt_village_reinforcements_c'),
			(party_set_slot,'p_village_37',slot_town_population,1000),
			(party_set_slot,'p_village_37',slot_town_population_max,5000),
			(party_set_slot,'p_village_37',slot_town_population_growth_factor,1),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_37',slot_town_demand_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_37',slot_town_storehouse_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_37',slot_town_facility_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_37',slot_town_surplus_array,'$return'),

			(party_set_slot,'p_village_38',slot_town_center,'scn_village'),
			(party_set_slot,'p_village_38',slot_town_castle,0),
			(party_set_slot,'p_village_38',slot_town_inn,0),
			(party_set_slot,'p_village_38',slot_town_store,0),
			(party_set_slot,'p_village_38',slot_town_smithy,0),
			(party_set_slot,'p_village_38',slot_town_capital,ueno),
			(party_set_slot,'p_village_38',slot_town_dojo,'scn_iga_dojo'),
			(party_set_slot,'p_village_38',slot_town_sensei,'trp_michimori'),
			(party_set_slot,'p_village_38',slot_town_kokujin,'trp_village_38_kokujin'),
			(party_set_slot,'p_village_38',slot_town_innkeeper,'trp_village_38_innkeeper'),
			(party_set_slot,'p_village_38',slot_town_merchant,'trp_village_38_merchant'),
			(party_set_slot,'p_village_38',slot_town_broker,null),
			(party_set_slot,'p_village_38',slot_town_moneychanger,null),
			(party_set_slot,'p_village_38',slot_town_fishmonger,'trp_village_38_fishmonger'),
			(party_set_slot,'p_village_38',slot_town_horse_trader,null),
			(party_set_slot,'p_village_38',slot_town_export_good,itm_kyoto_sake),
			(party_set_slot,'p_village_38',slot_town_export_rate,100),
			(party_set_slot,'p_village_38',slot_town_import_good,itm_salt),
			(party_set_slot,'p_village_38',slot_town_import_rate,100),
			(party_set_slot,'p_village_38',slot_town_terrain,ter_highland),
			(party_set_slot,'p_village_38',slot_town_size,ct_village),
			(party_set_slot,'p_village_38',slot_town_mercs,'p_village_38_mercs'),
			(party_set_slot,'p_village_38',slot_town_trade_hub,0),
			(call_script,'script_town_init_trade_dest','p_village_38',ueno,null,null,null,null,null),
			(party_set_slot,'p_village_38',slot_town_trade_month,10),
			(party_set_slot,'p_village_38',slot_town_att_to_player,att_cautious),
			(party_set_slot,'p_village_38',slot_town_player_relation,0),
			(party_set_slot,'p_village_38',slot_town_import_demand,3),
			(party_set_slot,'p_village_38',slot_town_export_demand,3),
			(party_set_slot,'p_village_38',slot_town_demand,0),
			(party_set_slot,'p_village_38',slot_town_treasury,3600),
			(party_set_slot,'p_village_38',slot_town_garrison_source,'p_village_garrison_source'),
			(party_set_slot,'p_village_38',slot_town_siege_active,0),
			(party_set_slot,'p_village_38',slot_town_under_siege,false),
			(party_set_slot,'p_village_38',slot_town_is_besieged_by,null),
			(party_set_slot,'p_village_38',slot_town_initial_faction,0),
			(party_set_slot,'p_village_38',slot_town_scene_flags,0),
			(party_set_slot,'p_village_38',slot_town_reserve_patrol,-1),
			(party_set_slot,'p_village_38',slot_town_spawn_points,1000),
			(party_set_slot,'p_village_38',slot_party_type,spt_city),
			(party_set_slot,'p_village_38',slot_party_food,5000),
			(party_set_slot,'p_village_38',slot_party_icon,'icon_village'),
			(party_set_slot,'p_village_38',slot_party_icon_state,tis_normal),
			(party_set_slot,'p_village_38',slot_party_ai_state,null),
			(party_set_slot,'p_village_38',slot_party_ai_object,null),
			(party_set_slot,'p_village_38',slot_town_accumulated_rents,0),
			(party_set_slot,'p_village_38',slot_town_accumulated_tariffs,0),
			(party_set_slot,'p_village_38',slot_town_current_improvement,null),
			(party_set_slot,'p_village_38',slot_town_improvement_end_hour,null),
			(party_set_slot,'p_village_38',slot_town_housing_level,1),
			(party_set_slot,'p_village_38',slot_town_irrigation_level,1),
			(party_set_slot,'p_village_38',slot_town_mill_level,1),
			(party_set_slot,'p_village_38',slot_town_raided_by,null),
			(party_set_slot,'p_village_38',slot_town_state,sts_normal),
			(party_set_slot,'p_village_38',slot_town_raid_progress,null),
			(party_set_slot,'p_village_38',slot_town_recover_progress,null),
			(party_set_slot,'p_village_38',slot_town_production_bonus,1),
			(party_set_slot,'p_village_38',slot_town_siege_days,0),
			(party_set_slot,'p_village_38',slot_town_reserve_patrol,null),
			(party_set_slot,'p_village_38',slot_town_trade_good_productions_begin,null),
			(party_set_slot,'p_village_38',slot_town_trade_good_temp_productions_begin,null),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_village_38',slot_town_trade_good_price_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_village_38',slot_town_trade_good_abundance_array,'$return'),
			(party_set_slot,'p_village_38',slot_town_tax_rate,100),
			(party_set_slot,'p_village_38',slot_town_shoen,null),
			(party_set_slot,'p_village_38',slot_town_prefecture_array,null),
			(party_set_slot,'p_village_38',slot_town_reinforcements_a,'pt_village_reinforcements_a'),
			(party_set_slot,'p_village_38',slot_town_reinforcements_b,'pt_village_reinforcements_b'),
			(party_set_slot,'p_village_38',slot_town_reinforcements_c,'pt_village_reinforcements_c'),
			(party_set_slot,'p_village_38',slot_town_population,1000),
			(party_set_slot,'p_village_38',slot_town_population_max,5000),
			(party_set_slot,'p_village_38',slot_town_population_growth_factor,1),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_38',slot_town_demand_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_38',slot_town_storehouse_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_38',slot_town_facility_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_38',slot_town_surplus_array,'$return'),

			(party_set_slot,'p_village_39',slot_town_center,'scn_village'),
			(party_set_slot,'p_village_39',slot_town_castle,0),
			(party_set_slot,'p_village_39',slot_town_inn,0),
			(party_set_slot,'p_village_39',slot_town_store,0),
			(party_set_slot,'p_village_39',slot_town_smithy,0),
			(party_set_slot,'p_village_39',slot_town_capital,ueno),
			(party_set_slot,'p_village_39',slot_town_dojo,0),
			(party_set_slot,'p_village_39',slot_town_sensei,-1),
			(party_set_slot,'p_village_39',slot_town_kokujin,'trp_village_39_kokujin'),
			(party_set_slot,'p_village_39',slot_town_innkeeper,'trp_village_39_innkeeper'),
			(party_set_slot,'p_village_39',slot_town_merchant,'trp_village_39_merchant'),
			(party_set_slot,'p_village_39',slot_town_broker,null),
			(party_set_slot,'p_village_39',slot_town_moneychanger,null),
			(party_set_slot,'p_village_39',slot_town_fishmonger,'trp_village_39_fishmonger'),
			(party_set_slot,'p_village_39',slot_town_horse_trader,null),
			(party_set_slot,'p_village_39',slot_town_export_good,itm_kyoto_sake),
			(party_set_slot,'p_village_39',slot_town_export_rate,100),
			(party_set_slot,'p_village_39',slot_town_import_good,itm_salt),
			(party_set_slot,'p_village_39',slot_town_import_rate,100),
			(party_set_slot,'p_village_39',slot_town_terrain,ter_highland),
			(party_set_slot,'p_village_39',slot_town_size,ct_village),
			(party_set_slot,'p_village_39',slot_town_mercs,'p_village_39_mercs'),
			(party_set_slot,'p_village_39',slot_town_trade_hub,0),
			(call_script,'script_town_init_trade_dest','p_village_39',otsu,null,null,null,null,null),
			(party_set_slot,'p_village_39',slot_town_trade_month,4),
			(party_set_slot,'p_village_39',slot_town_att_to_player,att_cautious),
			(party_set_slot,'p_village_39',slot_town_player_relation,0),
			(party_set_slot,'p_village_39',slot_town_import_demand,3),
			(party_set_slot,'p_village_39',slot_town_export_demand,3),
			(party_set_slot,'p_village_39',slot_town_demand,0),
			(party_set_slot,'p_village_39',slot_town_treasury,3600),
			(party_set_slot,'p_village_39',slot_town_garrison_source,'p_village_garrison_source'),
			(party_set_slot,'p_village_39',slot_town_siege_active,0),
			(party_set_slot,'p_village_39',slot_town_under_siege,false),
			(party_set_slot,'p_village_39',slot_town_is_besieged_by,null),
			(party_set_slot,'p_village_39',slot_town_initial_faction,0),
			(party_set_slot,'p_village_39',slot_town_scene_flags,0),
			(party_set_slot,'p_village_39',slot_town_reserve_patrol,-1),
			(party_set_slot,'p_village_39',slot_town_spawn_points,1000),
			(party_set_slot,'p_village_39',slot_party_type,spt_city),
			(party_set_slot,'p_village_39',slot_party_food,5000),
			(party_set_slot,'p_village_39',slot_party_icon,'icon_village'),
			(party_set_slot,'p_village_39',slot_party_icon_state,tis_normal),
			(party_set_slot,'p_village_39',slot_party_ai_state,null),
			(party_set_slot,'p_village_39',slot_party_ai_object,null),
			(party_set_slot,'p_village_39',slot_town_accumulated_rents,0),
			(party_set_slot,'p_village_39',slot_town_accumulated_tariffs,0),
			(party_set_slot,'p_village_39',slot_town_current_improvement,null),
			(party_set_slot,'p_village_39',slot_town_improvement_end_hour,null),
			(party_set_slot,'p_village_39',slot_town_housing_level,1),
			(party_set_slot,'p_village_39',slot_town_irrigation_level,1),
			(party_set_slot,'p_village_39',slot_town_mill_level,1),
			(party_set_slot,'p_village_39',slot_town_raided_by,null),
			(party_set_slot,'p_village_39',slot_town_state,sts_normal),
			(party_set_slot,'p_village_39',slot_town_raid_progress,null),
			(party_set_slot,'p_village_39',slot_town_recover_progress,null),
			(party_set_slot,'p_village_39',slot_town_production_bonus,1),
			(party_set_slot,'p_village_39',slot_town_siege_days,0),
			(party_set_slot,'p_village_39',slot_town_reserve_patrol,null),
			(party_set_slot,'p_village_39',slot_town_trade_good_productions_begin,null),
			(party_set_slot,'p_village_39',slot_town_trade_good_temp_productions_begin,null),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_village_39',slot_town_trade_good_price_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_village_39',slot_town_trade_good_abundance_array,'$return'),
			(party_set_slot,'p_village_39',slot_town_tax_rate,100),
			(party_set_slot,'p_village_39',slot_town_shoen,null),
			(party_set_slot,'p_village_39',slot_town_prefecture_array,null),
			(party_set_slot,'p_village_39',slot_town_reinforcements_a,'pt_village_reinforcements_a'),
			(party_set_slot,'p_village_39',slot_town_reinforcements_b,'pt_village_reinforcements_b'),
			(party_set_slot,'p_village_39',slot_town_reinforcements_c,'pt_village_reinforcements_c'),
			(party_set_slot,'p_village_39',slot_town_population,1000),
			(party_set_slot,'p_village_39',slot_town_population_max,5000),
			(party_set_slot,'p_village_39',slot_town_population_growth_factor,1),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_39',slot_town_demand_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_39',slot_town_storehouse_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_39',slot_town_facility_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_39',slot_town_surplus_array,'$return'),

			(party_set_slot,'p_village_40',slot_town_center,'scn_village'),
			(party_set_slot,'p_village_40',slot_town_castle,0),
			(party_set_slot,'p_village_40',slot_town_inn,0),
			(party_set_slot,'p_village_40',slot_town_store,0),
			(party_set_slot,'p_village_40',slot_town_smithy,0),
			(party_set_slot,'p_village_40',slot_town_capital,ueno),
			(party_set_slot,'p_village_40',slot_town_dojo,0),
			(party_set_slot,'p_village_40',slot_town_sensei,-1),
			(party_set_slot,'p_village_40',slot_town_kokujin,'trp_village_40_kokujin'),
			(party_set_slot,'p_village_40',slot_town_innkeeper,'trp_village_40_innkeeper'),
			(party_set_slot,'p_village_40',slot_town_merchant,'trp_village_40_merchant'),
			(party_set_slot,'p_village_40',slot_town_broker,null),
			(party_set_slot,'p_village_40',slot_town_moneychanger,null),
			(party_set_slot,'p_village_40',slot_town_fishmonger,'trp_village_40_fishmonger'),
			(party_set_slot,'p_village_40',slot_town_horse_trader,null),
			(party_set_slot,'p_village_40',slot_town_export_good,itm_kyoto_sake),
			(party_set_slot,'p_village_40',slot_town_export_rate,100),
			(party_set_slot,'p_village_40',slot_town_import_good,itm_salt),
			(party_set_slot,'p_village_40',slot_town_import_rate,100),
			(party_set_slot,'p_village_40',slot_town_terrain,ter_high_valley),
			(party_set_slot,'p_village_40',slot_town_size,ct_village),
			(party_set_slot,'p_village_40',slot_town_mercs,'p_village_40_mercs'),
			(party_set_slot,'p_village_40',slot_town_trade_hub,0),
			(call_script,'script_town_init_trade_dest','p_village_40',otsu,null,null,null,null,null),
			(party_set_slot,'p_village_40',slot_town_trade_month,7),
			(party_set_slot,'p_village_40',slot_town_att_to_player,att_cautious),
			(party_set_slot,'p_village_40',slot_town_player_relation,0),
			(party_set_slot,'p_village_40',slot_town_import_demand,3),
			(party_set_slot,'p_village_40',slot_town_export_demand,3),
			(party_set_slot,'p_village_40',slot_town_demand,0),
			(party_set_slot,'p_village_40',slot_town_treasury,3600),
			(party_set_slot,'p_village_40',slot_town_garrison_source,'p_village_garrison_source'),
			(party_set_slot,'p_village_40',slot_town_siege_active,0),
			(party_set_slot,'p_village_40',slot_town_under_siege,false),
			(party_set_slot,'p_village_40',slot_town_is_besieged_by,null),
			(party_set_slot,'p_village_40',slot_town_initial_faction,0),
			(party_set_slot,'p_village_40',slot_town_scene_flags,0),
			(party_set_slot,'p_village_40',slot_town_reserve_patrol,-1),
			(party_set_slot,'p_village_40',slot_town_spawn_points,1000),
			(party_set_slot,'p_village_40',slot_party_type,spt_city),
			(party_set_slot,'p_village_40',slot_party_food,5000),
			(party_set_slot,'p_village_40',slot_party_icon,'icon_village'),
			(party_set_slot,'p_village_40',slot_party_icon_state,tis_normal),
			(party_set_slot,'p_village_40',slot_party_ai_state,null),
			(party_set_slot,'p_village_40',slot_party_ai_object,null),
			(party_set_slot,'p_village_40',slot_town_accumulated_rents,0),
			(party_set_slot,'p_village_40',slot_town_accumulated_tariffs,0),
			(party_set_slot,'p_village_40',slot_town_current_improvement,null),
			(party_set_slot,'p_village_40',slot_town_improvement_end_hour,null),
			(party_set_slot,'p_village_40',slot_town_housing_level,1),
			(party_set_slot,'p_village_40',slot_town_irrigation_level,1),
			(party_set_slot,'p_village_40',slot_town_mill_level,1),
			(party_set_slot,'p_village_40',slot_town_raided_by,null),
			(party_set_slot,'p_village_40',slot_town_state,sts_normal),
			(party_set_slot,'p_village_40',slot_town_raid_progress,null),
			(party_set_slot,'p_village_40',slot_town_recover_progress,null),
			(party_set_slot,'p_village_40',slot_town_production_bonus,1),
			(party_set_slot,'p_village_40',slot_town_siege_days,0),
			(party_set_slot,'p_village_40',slot_town_reserve_patrol,null),
			(party_set_slot,'p_village_40',slot_town_trade_good_productions_begin,null),
			(party_set_slot,'p_village_40',slot_town_trade_good_temp_productions_begin,null),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_village_40',slot_town_trade_good_price_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(party_set_slot,'p_village_40',slot_town_trade_good_abundance_array,'$return'),
			(party_set_slot,'p_village_40',slot_town_tax_rate,100),
			(party_set_slot,'p_village_40',slot_town_shoen,null),
			(party_set_slot,'p_village_40',slot_town_prefecture_array,null),
			(party_set_slot,'p_village_40',slot_town_reinforcements_a,'pt_village_reinforcements_a'),
			(party_set_slot,'p_village_40',slot_town_reinforcements_b,'pt_village_reinforcements_b'),
			(party_set_slot,'p_village_40',slot_town_reinforcements_c,'pt_village_reinforcements_c'),
			(party_set_slot,'p_village_40',slot_town_population,1000),
			(party_set_slot,'p_village_40',slot_town_population_max,5000),
			(party_set_slot,'p_village_40',slot_town_population_growth_factor,1),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_40',slot_town_demand_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_40',slot_town_storehouse_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_40',slot_town_facility_array,'$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_poke','$return',':array_index',0),
			(try_end),
			(party_set_slot,'p_village_40',slot_town_surplus_array,'$return'),
			# Store intial town factions to slot_town_initial_faction, intialize trade good arrays
			(try_for_range,':town',cities_begin,villages_end),
				(store_faction_of_party,':faction',':town'),
				(call_script,'script_object_modify_slot',obj_party,':town',slot_town_initial_faction,op_asn,':faction'),
				(party_get_slot,':trade_good_abundance_array',':town',slot_town_trade_good_abundance_array),
				(party_get_slot,':trade_good_price_array',':town',slot_town_trade_good_price_array),
				(str_store_party_name,s11,':town'),
				# (display_log_message,'@{s11}:',debug_text),
				(str_clear,s10),
				(assign,':array_index',0),
				(try_for_range,':item',trade_goods_begin,trade_goods_end),
					(call_script,'script_calculate_abundance',':town',':item'),
					(call_script,'script_array_poke',':trade_good_abundance_array',':array_index',reg0),
					(store_item_value,reg1,':item'),
					(call_script,'script_array_poke',':trade_good_price_array',':array_index',reg1),
					(str_store_item_name,s12,':item'),
					(str_store_string,s10,'@{s10}{s12}: {reg0}, {reg1}; '),
					(val_add,':array_index',1),
				(try_end),
				# (display_log_message,'@{s10}',debug_text),
			(try_end),
			#Enryaku-ji Temple
			(party_set_slot,"p_temple_1", slot_town_center,0),
			(party_set_slot,"p_temple_1", slot_town_castle,"scn_temple"),
			(party_set_slot,"p_temple_1", slot_town_kokujin,"trp_temple_1_priest"),
			# Init troop genders and attitudes
			(try_for_range,reg1,"trp_city_1_kokujin","trp_temple_1_priest"),
	            (troop_set_slot,reg1,slot_troop_att_to_player,att_cautious),
	            (troop_set_slot,reg1,slot_troop_gender,0),
	        (try_end),
	        (try_for_range,reg2,"trp_town_1_innkeeper","trp_city_1_armorer"),
	            (troop_set_slot,reg2,slot_troop_gender,1),
	        (try_end),
			# Init twon garrisons
			(try_for_range,':town',hyogo,cities_end),
				(party_add_members,':town','trp_t3_heavy_cav_n',4),
				(party_add_members,':town','trp_t3_light_cav_n',5),
				(party_add_members,':town','trp_t2_spear_samurai_n',6),
				(party_add_members,':town','trp_t2_bow_ashigaru_n',10),
			(try_end),
			(try_for_range,':town',towns_begin,towns_end),
				(party_add_members,':town','trp_t2_light_cav_n',5),
				(party_add_members,':town','trp_t2_spear_samurai_n',6),
				(party_add_members,':town','trp_t2_crossbow_ashigaru_n',10),
			(try_end),
			(try_for_range,':town',villages_begin,villages_end),
				(party_add_members,':town','trp_veteran_defender',2),
				(party_add_members,':town','trp_village_defender',5),
				(party_add_members,':town','trp_farmer',8),
				(party_add_members,':town','trp_villager',8),
			(try_end),
			# initial rice production
			(try_for_range,':town',cities_begin,villages_end),
				(call_script,'script_rice_production',':town'),
			(try_end),
			# initial faction strength
			(call_script,'script_faction_strength','fac_hosokawa',0),
			(call_script,'script_faction_strength','fac_yamana',0),
			# trade goods, production and prices
			(try_for_range,':item',trade_goods_begin,trade_goods_end),
				(try_for_range,':city',cities_begin,villages_end),
					(call_script,'script_center_set_trade_good_production',':town',':item',0),
				(try_end),
			(try_end),
			(try_for_range,':city',cities_begin,villages_end),
				(call_script,'script_update_trade_good_price_for_party',':city'),
			(try_end),
			(try_for_range,':item',trade_goods_begin,trade_goods_end),
				(try_for_range,':city',cities_begin,villages_end),
					(store_sub,':item_price_slot',':item',trade_goods_begin),
					(val_add,':item_price_slot',slot_town_trade_good_prices_begin),
					(party_set_slot,':city',':item_price_slot',1000),
				(try_end),
			(try_end),
			# update weaponsmith, armorer, goods merchant inventory
			(try_begin),
				(try_for_range,':town',cities_begin,towns_end),
					(party_get_slot,':weaponsmith',':town',slot_town_weaponsmith),
					(reset_item_probabilities,100),
					(store_random_in_range,':quality',90,111),
					(set_merchandise_modifier_quality,':quality'),
					(troop_add_merchandise,':weaponsmith',itp_type_one_handed_wpn,5),
					(troop_add_merchandise,':weaponsmith',itp_type_two_handed_wpn,5),
					(troop_add_merchandise,':weaponsmith',itp_type_polearm,5),
					(troop_add_merchandise,':weaponsmith',itp_type_bow,4),
					(troop_add_merchandise,':weaponsmith',itp_type_arrows,2),
					(troop_add_merchandise,':weaponsmith',itp_type_thrown,2),
					(troop_ensure_inventory_space,':weaponsmith',merchant_inventory_space),
					(store_troop_gold,':merchant_gold',':weaponsmith'),
					(lt,':merchant_gold',15000),
					(store_random_in_range,':new_merchant_gold',360,3600),
					(val_add,':new_merchant_gold',360),
					(troop_add_gold,':weaponsmith',':new_merchant_gold'),
				(try_end),
				(try_for_range,':town',cities_begin,towns_end),
					(party_get_slot,':armorer',':town',slot_town_armorer),
					(reset_item_probabilities,100),
					(store_random_in_range,':quality',90,111),
					(set_merchandise_modifier_quality,':quality'),
					(troop_add_merchandise,':armorer',itp_type_body_armor,12),
					(troop_add_merchandise,':armorer',itp_type_head_armor,12),
					(troop_add_merchandise,':armorer',itp_type_foot_armor,8),
					(troop_add_merchandise,':armorer',itp_type_hand_armor,4),
					(troop_ensure_inventory_space,':armorer',merchant_inventory_space),
					(store_troop_gold,':merchant_gold',':armorer'),
					(lt,':merchant_gold',45000),
					(store_random_in_range,':new_merchant_gold',3600,14400),
					(val_add,':new_merchant_gold',1800),
					(troop_add_gold,':armorer',':new_merchant_gold'),
				(try_end),
				(try_for_range,':town',cities_begin,villages_end),
					(party_get_slot,':goods_merchant',':town',slot_town_merchant),
					(reset_item_probabilities,100),
					(reset_price_rates),
					(store_random_in_range,reg1,90,111),
					(set_merchandise_modifier_quality,reg1),
					(party_get_slot,':trade_good_abundance_array',':town',slot_town_trade_good_abundance_array),
					(assign,':array_index',0),
					(try_for_range,":item",trade_goods_begin,trade_goods_end),
						(call_script,'script_array_peek',':trade_good_abundance_array',':array_index'),
						(set_item_probability_in_merchandise,":item",'$return'),
						(val_add,':array_index',1),
					(try_end),
					(troop_add_merchandise,":goods_merchant",itp_type_goods,num_merchandise_goods),
					(call_script,'script_troop_remove_items',':goods_merchant',rice_goods_begin,food_end),
					(troop_add_merchandise,':goods_merchant',itp_type_horse,12),
					(troop_ensure_inventory_space,":goods_merchant",merchant_inventory_space),
					(store_troop_gold, ":merchant_gold",":goods_merchant"),
					(try_begin),
						(lt,":merchant_gold",20000),
						(store_random_in_range,":new_merchant_gold",1000,3000),
						(troop_add_gold,":goods_merchant",":new_merchant_gold"),
					(try_end),
					# update fishmonger inventory
					(party_get_slot,':fishmonger',':town',slot_town_fishmonger),
					(call_script,'script_troop_add_merchandise',':town',':fishmonger',food_begin,food_end,15,30,0),
					(store_troop_gold, ":merchant_gold",":fishmonger"),
					(try_begin),
						(lt,":merchant_gold",5000),
						(store_random_in_range,":new_merchant_gold",500,1000),
						(troop_add_gold,":fishmonger",":new_merchant_gold"),
					(try_end),
					(troop_ensure_inventory_space,":fishmonger",merchant_inventory_space),
					# update sake merchant/broker inventory
					(try_begin),
						(party_slot_neq,':town',slot_town_broker,null),
						(party_get_slot,':broker',':town',slot_town_broker),
						(call_script,'script_troop_add_merchandise',':town',':broker',rice_goods_begin,rice_goods_end,20,30,100),
						(store_troop_gold, ":merchant_gold",":broker"),
						(try_begin),
							(lt,":merchant_gold",50000),
							(store_random_in_range,":new_merchant_gold",5000,10000),
							(troop_add_gold,":broker",":new_merchant_gold"),
						(try_end),
						(troop_ensure_inventory_space,":broker",merchant_inventory_space),
					(try_end),
				(try_end),
			(try_end),
			(call_script, "script_update_party_creation_random_limits"),
		    (try_for_range,':troop','trp_hosokawa_katsumoto','trp_haruko'),
				(troop_set_slot,':troop',slot_troop_quest,null),
			(try_end),
			(try_for_range,':unused',0,10),
				(call_script,'script_spawn_bandits'),
			(try_end),
			(call_script,'script_initialize_starting_facilities'),
			(try_for_range,':town',cities_begin,villages_end),
				(call_script,'script_town_check_supply_and_demand',':town'),
			(try_end),
			]
		),
  
  
  # script_game_event_party_encounter:
  # This script is called from the game engine whenever player party encounters another party or a battle on the world map
  # INPUT:
  # param1: encountered_party
  # param2: second encountered_party (if this was a battle
("game_event_party_encounter",
    [
      (store_script_param_1, "$g_encountered_party"),
      (store_script_param_2, "$g_encountered_party_2"),# encountered_party2 is set when we come across a battle or siege, otherwise it's a negative value
      (store_faction_of_party, "$g_encountered_party_faction","$g_encountered_party"),
      (store_relation, "$g_encountered_party_relation", "$g_encountered_party_faction", "fac_player_faction"),
      (party_get_slot, "$g_encountered_party_type", "$g_encountered_party", slot_party_type),
      (party_get_template_id,"$g_encountered_party_template","$g_encountered_party"),
      (try_begin),
        (gt, "$g_encountered_party_2", 0),
        #         (store_faction_of_party, "$g_encountered_party_2_faction","$g_encountered_party_2"),
        #         (store_relation, "$g_encountered_party_2_relation", "$g_encountered_party_2_faction", "fac_player_faction"),
        #         (party_get_template_id,"$g_encountered_party_2_template","$g_encountered_party_2"),
      (else_try),
        #         (assign, "$g_encountered_party_2_faction",-1),
        #         (assign, "$g_encountered_party_2_relation", 0),
        #         (assign,"$g_encountered_party_2_template", -1),
      (try_end),
	  (assign,'$g_current_town',-1),
      (assign, "$g_last_rest_center", -1),
	  (assign,'$g_city_scene_last_visited',0),
      (assign, "$g_talk_context", 0),
      (assign,"$g_player_surrenders",0),
      (assign,"$g_enemy_surrenders",0),
      (assign, "$g_leave_encounter",0),
      (assign, "$g_engaged_enemy", 0),
      (assign, "$g_mission_remaining_horses", 0),
      (assign,"$waiting_for_arena_fight_result", 0),
      (assign,"$arena_bet_amount",0),
      #       (assign,"$g_player_raiding_village",0),
      (rest_for_hours, 0), #stop waiting
      #       (assign, "$g_permitted_to_center",0),
      (assign, "$new_encounter", 1), #check this in the menu.
      (try_begin),
        (lt, "$g_encountered_party_2",0), #Normal encounter. Not battle or siege.
        (party_get_template_id,reg60,"$g_encountered_party"),
		(try_begin),
		   (eq,reg60,'pt_traveling_peddler'),
		   (assign,'$encounter_merchant',1),
		(try_end),
		(try_begin),
		   (eq, "$g_encountered_party", south_kyoto),
		   (assign,'$g_current_town','$g_encountered_party'),
		   (party_get_slot,'$g_town_kokujin','$g_encountered_party',slot_town_kokujin),
		   (party_get_slot,'$g_town_sensei','$g_encountered_party',slot_town_sensei),
		   (jump_to_menu, "mnu_city"),
		(else_try),
		   (is_between, "$g_encountered_party", west_kyoto, hyogo),
		   (assign,'$g_current_town','$g_encountered_party'),
		   (jump_to_menu, "mnu_null"),
		(else_try),
		   (is_between,"$g_encountered_party",'p_city_5','p_town_1'),
		   (assign,'$g_current_town','$g_encountered_party'),
		   (party_get_slot,'$g_town_kokujin','$g_encountered_party',slot_town_kokujin),
		   (party_get_slot,'$g_town_sensei','$g_encountered_party',slot_town_sensei),
		   (jump_to_menu, "mnu_city"),
		(else_try),
		   (is_between,"$g_encountered_party", 'p_town_1','p_village_1'),
		   (assign,'$g_current_town','$g_encountered_party'),
		   (party_get_slot,'$g_town_kokujin','$g_encountered_party',slot_town_kokujin),
		   (party_get_slot,'$g_town_sensei','$g_encountered_party',slot_town_sensei),
		   (jump_to_menu, "mnu_town"),
		(else_try),
		   (is_between,"$g_encountered_party",'p_village_1','p_temple_1'),
		   (assign,'$g_current_town','$g_encountered_party'),
		   (party_get_slot,'$g_town_kokujin','$g_encountered_party',slot_town_kokujin),
		   (party_get_slot,'$g_town_sensei','$g_encountered_party',slot_town_sensei),
		   (jump_to_menu, "mnu_village"),
		(else_try),
		   (call_script,'script_cf_party_is_of_template','$g_encountered_party','pt_army'),
		   (jump_to_menu, "mnu_army"),
		(else_try),
		   (eq, "$g_encountered_party", "p_temple_1"),
		   (jump_to_menu, "mnu_temple"),
		(else_try),
		   (eq, "$g_encountered_party", "p_bandit_camp"),
		   (jump_to_menu, "mnu_bandit_camp"),
		(else_try),
		   (eq,reg60,'pt_fort'),
		   (jump_to_menu,'mnu_fort'),
		(else_try),
		   (eq,reg60, "pt_bandit_raiders_a"),
		   (check_quest_active,'qst_intro_kuge_deliver_msg'),
		   (jump_to_menu, "mnu_intro_kuge_quest"),
		(else_try),
		   (eq,reg60,'pt_duelist'),
		   (jump_to_menu,'mnu_duelist'),
		(else_try),
		   (eq,reg60,'pt_traveling_peddler'),
		   (jump_to_menu,'mnu_travelling_peddler'),
		(else_try),
           (eq, "$g_encountered_party", "p_camp_bandits"),
           (jump_to_menu, "mnu_camp"),
		(else_try),
		   (assign,'$g_most_recent_spawn','$g_encountered_party'),
		   (jump_to_menu,'mnu_simple_encounter'),
		(try_end),
      (else_try), #Battle or siege
        (try_begin),
          (this_or_next|party_slot_eq, "$g_encountered_party", slot_party_type, spt_town),
          (party_slot_eq, "$g_encountered_party", slot_party_type, spt_castle),
          (try_begin),
            (eq, "$auto_enter_town", "$g_encountered_party"),
            (jump_to_menu, "mnu_town"),
          #(else_try),
          #  (eq, "$auto_besiege_town", "$g_encountered_party"),
          #  (jump_to_menu, "mnu_besiegers_camp_with_allies"),
          #(else_try),
          #  (jump_to_menu, "mnu_join_siege_outside"),
          (try_end),
        (else_try),
          (jump_to_menu, "mnu_pre_join"),
        (try_end),
      (try_end),
      (assign,"$auto_enter_town",0),
      (assign,"$auto_besiege_town",0),
  ]),
  
  #script_game_event_simulate_battle:
  # This script is called whenever the game simulates the battle between two parties on the map.
  # INPUT:
  # param1: Defender Party
  # param2: Attacker Party
("game_event_simulate_battle",
    [
      (store_script_param_1, ":root_defender_party"),
      (store_script_param_2, ":root_attacker_party"),
      
      (try_begin),
        (this_or_next|party_slot_eq, ":root_defender_party", slot_party_retreat_flag, 1),
        (party_slot_eq, ":root_attacker_party", slot_party_retreat_flag, 1),
        (set_trigger_result, 1), #End battle!
      (try_end),
      (party_set_slot, ":root_attacker_party", slot_party_retreat_flag, 0),
      
      (assign, ":cancel_attack", 0),
      
      (try_begin),
        (neg|is_currently_night), #Don't fight at night???
        (party_collect_attachments_to_party, ":root_defender_party", "p_collective_ally"),
        (party_collect_attachments_to_party, ":root_attacker_party", "p_collective_enemy"),
        
        (call_script, "script_party_count_fit_regulars", "p_collective_ally"),
        (assign, ":defender_strength", reg0),
        (call_script, "script_party_count_fit_regulars", "p_collective_enemy"),
        (assign, ":attacker_strength", reg0),
        
        (val_min, ":defender_strength", 30),
        (val_min, ":attacker_strength", 30),
        
        
        (try_begin),
          #For sieges increase attacker casualties and reduce defender casualties.
          (this_or_next|party_slot_eq, ":root_defender_party", slot_party_type, spt_castle),
          (party_slot_eq, ":root_defender_party", slot_party_type, spt_town),
          (val_mul, ":defender_strength", 2),
          (val_div, ":attacker_strength", 2),
        (try_end),
        
        (inflict_casualties_to_party_group, ":root_attacker_party", ":defender_strength", "p_temp_casualties"),
        (party_collect_attachments_to_party, ":root_attacker_party", "p_collective_enemy"),
        #         (call_script, "script_party_count_fit_regulars", "p_collective_enemy"),
        (call_script, "script_party_calculate_regular_strength", "p_collective_enemy"),
        (assign, ":new_attacker_strength", reg0),
        
        (try_begin),
          (gt, ":new_attacker_strength", 0),
          (inflict_casualties_to_party_group, ":root_defender_party", ":attacker_strength", "p_temp_casualties"),
        (try_end),
        (party_collect_attachments_to_party, ":root_defender_party", "p_collective_ally"),
        #         (call_script, "script_party_count_fit_regulars", "p_collective_ally"),
        (call_script, "script_party_calculate_regular_strength", "p_collective_ally"),
        (assign, ":new_defender_strength", reg0),
        
        (try_begin),
          (party_slot_eq, ":root_defender_party", slot_party_type, spt_town),
          (party_slot_eq, ":root_attacker_party", slot_party_type, spt_castle),
          (store_mul, ":attacker_advantage", ":new_attacker_strength", 1),
          (store_mul, ":defender_advantage", ":new_defender_strength", 4),
        (else_try),
          (store_mul, ":attacker_advantage", ":new_attacker_strength", 2),
          (store_mul, ":defender_advantage", ":new_defender_strength", 3),
        (try_end),
        
        (try_begin),
          (lt, ":attacker_advantage",":defender_advantage"),
          (assign, ":cancel_attack", 1),
        (try_end),
        
        
        (try_begin),
          (this_or_next|eq, ":new_attacker_strength", 0),
          (eq, ":new_defender_strength", 0),
          # Battle concluded! determine winner
          
          (try_begin),
            (eq, ":new_attacker_strength", 0),
            (assign, ":root_winner_party",   ":root_defender_party"),
            (assign, ":root_defeated_party", ":root_attacker_party"),
            (assign, ":collective_casualties",    "p_collective_enemy"),
          (else_try),
            (assign, ":root_winner_party", ":root_attacker_party"),
            (assign, ":root_defeated_party",  ":root_defender_party"),
            (assign, ":collective_casualties",  "p_collective_ally"),
          (try_end),
          
          (call_script, "script_get_nonempty_party_in_group", ":root_winner_party"),
          (assign, ":nonempty_winner_party", reg0),
          (ge, ":nonempty_winner_party", 0),
          
          (store_faction_of_party, ":faction_receiving_prisoners", ":nonempty_winner_party"),
          (store_faction_of_party, ":defeated_faction", ":root_defeated_party"),
          
          (party_get_num_companion_stacks, ":num_stacks", ":collective_casualties"),
          (try_for_range, ":troop_iterator", 0, ":num_stacks"),
            (party_stack_get_troop_id, ":cur_troop_id", ":collective_casualties", ":troop_iterator"),
            (troop_is_hero, ":cur_troop_id"),
            (troop_set_slot, ":cur_troop_id", slot_troop_is_prisoner, 0),
            (troop_set_slot, ":cur_troop_id", slot_troop_leaded_party, -1),
            (store_random_in_range, ":rand", 0, 100),
            (try_begin),
              (ge, ":rand", hero_escape_after_defeat_chance),
              (party_add_prisoners, ":nonempty_winner_party", ":cur_troop_id", 1),
              (gt, reg0, 0),
              (troop_set_slot, ":cur_troop_id", slot_troop_is_prisoner, 1),
              (display_log_message,"str_hero_taken_prisoner"),
            (else_try),
              (str_store_troop_name, s1, ":cur_troop_id"),
              (str_store_faction_name, s2, ":faction_receiving_prisoners"),
              (str_store_faction_name, s3, ":defeated_faction"),
              (display_log_message,"@{s1} of {s3} was defeated in battle but managed to escape."),
            (try_end),
          (try_end),
          (party_get_num_prisoner_stacks, ":num_stacks", ":collective_casualties"),
          (try_for_range, ":troop_iterator", 0, ":num_stacks"),
            (party_prisoner_stack_get_troop_id, ":cur_troop_id", ":collective_casualties", ":troop_iterator"),
            (troop_is_hero, ":cur_troop_id"),
            (troop_set_slot, ":cur_troop_id", slot_troop_is_prisoner, 0),
            (str_store_troop_name, s1, ":cur_troop_id"),
            (str_store_faction_name, s2, ":faction_receiving_prisoners"),
            (str_store_faction_name, s3, ":defeated_faction"),
            (display_log_message,"str_hero_freed"),
          (try_end),
          
          (party_clear, "p_temp_party"),
          (assign, "$g_move_heroes", 0), #heroes are already processed above. Skip them here.
          (call_script, "script_party_add_party_prisoners", "p_temp_party", ":collective_casualties"),
          (call_script, "script_party_prisoners_add_party_companions", "p_temp_party", ":collective_casualties"),
          (distribute_party_among_party_group, "p_temp_party", ":root_winner_party"),
          (call_script, "script_clear_party_group", ":root_defeated_party"),
          (set_trigger_result, 1), #End battle!
          
          
          #Center captured
          (try_begin),
            (party_get_slot, ":cur_party_type", ":root_defeated_party", slot_party_type),
            (this_or_next|eq, ":cur_party_type", spt_town),
            (eq, ":cur_party_type", spt_castle),
            
            (store_faction_of_party, ":winner_faction", ":root_winner_party"),
            (store_faction_of_party, ":defeated_faction", ":root_defeated_party"),
            
            (str_store_party_name, s1, ":root_defeated_party"),
            (str_store_faction_name, s2, ":winner_faction"),
            (str_store_faction_name, s3, ":defeated_faction"),
            (display_log_message, "str_center_captured"),
            
            #(try_begin),
            #  (party_get_num_companion_stacks, ":num_stacks", ":root_winner_party"),
            #  (gt, ":num_stacks", 0),
            #  (party_stack_get_troop_id, ":leader_troop_no", ":root_winner_party", 0),
            #  (is_between, ":leader_troop_no", kingdom_heroes_begin, kingdom_heroes_end),
            #  (party_set_slot, ":root_defeated_party", slot_center_last_taken_by_troop, ":leader_troop_no"),
            #(else_try),
            #  (party_set_slot, ":root_defeated_party", slot_center_last_taken_by_troop, -1),
            #(try_end),
            
            (call_script, "script_give_center_to_faction", ":root_defeated_party", ":winner_faction"),
            (party_set_slot, ":root_winner_party", slot_party_ai_state, spai_undefined),
            (party_set_ai_behavior, ":root_winner_party", ai_bhvr_travel_to_party),
            (party_set_flags, ":root_winner_party", pf_default_behavior, 0),
          (try_end),
        (try_end),
        # (try_begin),
			# (call_script,'script_cf_party_is_of_template',':root_defeated_party','pt_trade_caravan'),
			# (call_script,'script_gc_destroy_caravan',':root_defeated_party'),
		# (try_end),
        #ADD XP
        (try_begin),
          (party_slot_eq, ":root_attacker_party", slot_party_type, spt_kingdom_hero_party),
          (store_random_in_range, ":random_num",0, 100),
          (lt, ":random_num", 25),
          (gt, ":new_attacker_strength", 0),
          (call_script, "script_upgrade_hero_party", ":root_attacker_party", 1000),
        (try_end),
        (try_begin),
          (party_slot_eq, ":root_defender_party", slot_party_type, spt_kingdom_hero_party),
          (store_random_in_range, ":random_num",0, 100),
          (lt, ":random_num", 25),
          (gt, ":new_defender_strength", 0),
          (call_script, "script_upgrade_hero_party", ":root_defender_party", 1000),
        (try_end),
        
        (store_random_in_range, ":random_num",0, 100),
        (try_begin),
          (this_or_next|lt, ":random_num", 20),
          (eq, ":cancel_attack", 1),
          (set_trigger_result, 1), #End battle!
        (try_end),
      (try_end),
		]),
  
  #script_game_get_item_buy_price_factor:
  # This script is called from the game engine for calculating the buying price of any item.
  # INPUT:
  # param1: item_kind_id
  # OUTPUT:
  # trigger_result and reg0 = price_factor
("game_get_item_buy_price_factor",
	[
		(store_script_param_1, ":item_kind_id"),
		(assign, ":price_factor", 100),

		(call_script, "script_get_trade_penalty", ":item_kind_id"),
		(assign, ":trade_penalty", reg0),
		(assign,':price_factor',100),
		#(display_message,'@Trade penalty {reg0}'),
		#(try_begin),
		#  (is_between, ":item_kind_id", trade_goods_begin, trade_goods_end),
		#  (store_sub, ":item_slot_no", ":item_kind_id", trade_goods_begin),
		#  (val_add, ":item_slot_no", slot_town_trade_good_prices_begin),
		#  (party_get_slot, ":price_factor", "$g_encountered_party", ":item_slot_no"),
		#  (val_mul, ":price_factor", 100), #normalize price factor to range 0..100
		#  (val_div, ":price_factor", average_price_factor),
		#(try_end),

		(store_add, ":penalty_factor", 100, ":trade_penalty"),

		(val_mul, ":price_factor", ":penalty_factor"),
		(val_div, ":price_factor", 100),
		(assign, reg0, ":price_factor"),
		(set_trigger_result, reg0),
		]
	),
  
#script_game_get_item_sell_price_factor:
# This script is called from the game engine for calculating the selling price of any item.
# INPUT:
# param1: item_kind_id
# OUTPUT:
# trigger_result and reg0 = price_factor
("game_get_item_sell_price_factor",
    [
		(store_script_param_1, ":item_kind_id"),
		(assign, ":price_factor", 100),
		(call_script, "script_get_trade_penalty", ":item_kind_id"),
		(assign, ":trade_penalty", reg0),
		#(try_begin),
		#  (is_between, ":item_kind_id", trade_goods_begin, trade_goods_end),
		#  (store_sub, ":item_slot_no", ":item_kind_id", trade_goods_begin),
		#  (val_add, ":item_slot_no", slot_town_trade_good_prices_begin),
		#  (party_get_slot, ":price_factor", "$g_encountered_party", ":item_slot_no"),
		#  (val_mul, ":price_factor", 100),#normalize price factor to range 0..100
		#  (val_div, ":price_factor", average_price_factor),
		#(else_try),
		#increase trade penalty while selling
		#  (val_mul, ":trade_penalty", 3),
		#  (val_div, ":trade_penalty", 2),
		#(try_end),
		(store_add, ":penalty_divisor", 100, ":trade_penalty"),
		(val_mul, ":price_factor", 100),
		(val_div, ":price_factor", ":penalty_divisor"),
		(try_begin),
			(is_between,':item_kind_id','itm_string_of_coins','itm_waraji_a'),
			(assign,':price_factor',0),
		(try_end),
		(assign, reg0, ":price_factor"),
		(set_trigger_result, reg0),
		]
	),
  
  # script_get_trade_penalty
  #
  # Input:
  # param1: troop_id,
  # Output: reg0
  
("get_trade_penalty",
    [
      (store_script_param_1, ":item_kind_id"),
      (assign, ":penalty",0),
      
      (party_get_skill_level, ":trade_skill", "p_main_party", skl_trade),
      (try_begin),
        (is_between, ":item_kind_id", trade_goods_begin, trade_goods_end),
        (assign, ":penalty",17),
        (store_mul, ":skill_bonus", ":trade_skill", 1),
        (val_sub, ":penalty", ":skill_bonus"),
      (else_try),
        (assign, ":penalty",100),
        (store_mul, ":skill_bonus", ":trade_skill", 5),
        (val_sub, ":penalty", ":skill_bonus"),
      (try_end),
      
      # Apply penalty if player is hostile to merchants faction
      (assign, ":merchants_relation_multiplier", 1000),
      (store_relation, ":merchants_reln", "fac_merchants", "fac_player_faction"),
      (try_begin),
        (lt, ":merchants_reln", 0),
        (store_sub, ":merchants_reln_dif", 10, ":merchants_reln"),
        (store_mul, ":merchants_relation_penalty", ":merchants_reln_dif", 20),
        (val_add, ":merchants_relation_multiplier", ":merchants_relation_penalty"),
      (try_end),
      
      # Apply penalty if player is on bad terms with the merchant
      (troop_get_slot, ":troop_reln", "$g_talk_troop", slot_troop_player_relation),
      (try_begin),
        (lt, ":troop_reln", 0),
        (store_sub, ":troop_reln_dif", 0, ":troop_reln"),
        (store_mul, ":troop_relation_penalty", ":troop_reln_dif", 20),
        (val_add, ":merchants_relation_multiplier", ":troop_relation_penalty"),
      (try_end),
      
      (val_mul, ":penalty",  ":merchants_relation_multiplier"),
      (val_div, ":penalty", 1000),
      (assign, reg0, ":penalty"),
  ]),
  
  #script_game_event_buy_item:
  # This script is called from the game engine when player buys an item.
  # INPUT:
  # param1: item_kind_id
("game_event_buy_item",
    [
      (store_script_param_1, ":item_kind_id"),
      (store_script_param_2, ":reclaim_mode"),
      (item_set_slot,':item_kind_id',slot_item_durability,100),
      (try_begin),
        (is_between, ":item_kind_id", trade_goods_begin, trade_goods_end),
        (store_sub, ":item_slot_no", ":item_kind_id", trade_goods_begin),
        (val_add, ":item_slot_no", slot_town_trade_good_prices_begin),
        (party_get_slot, ":multiplier", "$g_encountered_party", ":item_slot_no"),
        (try_begin),
          (eq, ":reclaim_mode", 0),
          (val_add, ":multiplier", 10),
        (else_try),
          (val_add, ":multiplier", 15),
        (try_end),
        (val_min, ":multiplier", maximum_price_factor),
        (party_set_slot, "$g_encountered_party", ":item_slot_no", ":multiplier"),
      (try_end),
  ]),
  
  #script_game_event_sell_item:
  # This script is called from the game engine when player sells an item.
  # INPUT:
  # param1: item_kind_id
("game_event_sell_item",
    [
      (store_script_param_1, ":item_kind_id"),
      (store_script_param_2, ":return_mode"),
      (try_begin),
        (is_between, ":item_kind_id", trade_goods_begin, trade_goods_end),
        (store_sub, ":item_slot_no", ":item_kind_id", trade_goods_begin),
        (val_add, ":item_slot_no", slot_town_trade_good_prices_begin),
        (party_get_slot, ":multiplier", "$g_encountered_party", ":item_slot_no"),
        (try_begin),
          (eq, ":return_mode", 0),
          (val_sub, ":multiplier", 15),
        (else_try),
          (val_sub, ":multiplier", 10),
        (try_end),
        (val_max, ":multiplier", minimum_price_factor),
        (party_set_slot, "$g_encountered_party", ":item_slot_no", ":multiplier"),
      (try_end),
  ]),
  
  
  # script_game_get_troop_wage
  # This script is called from the game engine for calculating troop wages.
  # Input:
  # param1: troop_id, param2: party-id
  # Output: reg0: weekly wage
  
("game_get_troop_wage",
    [
      (store_script_param_1, ":troop_id"),
      (store_script_param_2, ":unused"), #party id
      
      # (assign,":wage", 0),
      # (try_begin),
        # (troop_is_hero, ":troop_id"),
      # (else_try),
		# (troop_get_inventory_slot,':horse_slot',':troop_id',ek_horse),
		# (assign,':horse_mod',1),
		# (try_begin),
			# (gt,':horse_slot',0),
			# (assign,':horse_mod',5),
		# (try_end),
		# (store_character_level, ":troop_level", ":troop_id"),
        # (val_add, ":troop_level", 5),
		# (val_mul,':troop_level',':troop_level'),
		# (val_mul,':troop_level',':troop_level'),
		# (val_mul,':troop_level',':troop_level'),
		# (val_div, ":wage", 30),
		# (val_mul,':wage',':horse_mod'),
      # (try_end),
      # (assign, reg0, ":wage"),
	  (troop_get_slot,reg0,':troop_id',slot_troop_cost),
      (set_trigger_result, reg0),
  ]),
  
  # script_game_get_join_cost
  # This script is called from the game engine for calculating troop join cost.
  # Input:
  # param1: troop_id,
  # Output: reg0: weekly wage
  
("game_get_join_cost",
    [
      (store_script_param_1, ":troop_id"),
      
      (assign,":join_cost", 0),
      (try_begin),
        (troop_is_hero, ":troop_id"),
      (else_try),
        (troop_get_slot,':join_cost',':troop_id',slot_troop_cost),
		(val_mul,':join_cost',5),
		(val_div,':join_cost',2),
      (try_end),
      (assign, reg0, ":join_cost"),
      (set_trigger_result, reg0),
  ]),
  
  # script_game_get_prisoner_price
  # This script is called from the game engine for calculating prisoner price
  # Input:
  # param1: troop_id,
  # Output: reg0
  
("game_get_prisoner_price",
    [
      (store_script_param_1, ":troop_id"),
      (store_character_level, ":troop_level", ":troop_id"),
	  (set_fixed_point_multiplier,1000),
	  (store_mul,':ransom_amount',':troop_level',1500),
	  (val_div, ":ransom_amount", 6),
	  (val_mul,':ransom_amount',360),
	  (val_max,':ransom_amount',360),
	  (convert_from_fixed_point,':ransom_amount'),
	  (assign,reg0,':ransom_amount'),
      (set_trigger_result,reg0),
  ]),
  
  
  # script_game_check_prisoner_can_be_sold
  # This script is called from the game engine for checking if a given troop can be sold.
  # Input:
  # param1: troop_id,
  # Output: reg0: 1= can be sold; 0= can not be sold.
  
("game_check_prisoner_can_be_sold",
    [
      (store_script_param_1, ":troop_id"),
      (assign, reg0, 0),
      (try_begin),
        (neg|troop_is_hero, ":troop_id"),
        (assign, reg0, 1),
      (try_end),
      (set_trigger_result, reg0),
  ]),
  
  #script_game_event_inspect_party:
  # This script is called from the game engine when player party inspects another party.
  # INPUT:
  # param1: Party-id
("game_event_inspect_party",
    [
  ]),
  
  #script_game_get_statistics_line:
  # This script is called from the game engine when statistics page is opened.
  # INPUT:
  # param1: line_no
("game_get_statistics_line",
    [
      (store_script_param_1, ":line_no"),
      (try_begin),
        (eq, ":line_no", 0),
        (get_player_agent_kill_count, reg1),
        (str_store_string, s1, "str_number_of_troops_killed_reg1"),
        (set_result_string, s1),
      (else_try),
        (eq, ":line_no", 1),
        (get_player_agent_kill_count, reg1, 1),
        (str_store_string, s1, "str_number_of_troops_wounded_reg1"),
        (set_result_string, s1),
      (else_try),
        (eq, ":line_no", 2),
        (get_player_agent_own_troop_kill_count, reg1),
        (str_store_string, s1, "str_number_of_own_troops_killed_reg1"),
        (set_result_string, s1),
      (else_try),
        (eq, ":line_no", 3),
        (get_player_agent_own_troop_kill_count, reg1, 1),
        (str_store_string, s1, "str_number_of_own_troops_wounded_reg1"),
        (set_result_string, s1),
      (try_end),
  ]),
  
  #script_game_get_date_text:
  # This script is called from the game engine when the date needs to be displayed.
  # INPUT: arg1 = number of days passed since the beginning of the game
  # OUTPUT: result string = date
("game_get_date_text",
    [
      (store_script_param_1, ":num_days"),
      (store_add, ":cur_day", ":num_days", 1),
      (assign, ":cur_month", 7),
      (assign, ":cur_year", 1467),
      (assign, ":try_range", 99999),
      (try_for_range, ":unused", 0, ":try_range"),
        (try_begin),
          (this_or_next|eq, ":cur_month", 1),
          (this_or_next|eq, ":cur_month", 3),
          (this_or_next|eq, ":cur_month", 5),
          (this_or_next|eq, ":cur_month", 7),
          (this_or_next|eq, ":cur_month", 8),
          (this_or_next|eq, ":cur_month", 10),
          (eq, ":cur_month", 12),
          (assign, ":month_day_limit", 31),
        (else_try),
          (this_or_next|eq, ":cur_month", 4),
          (this_or_next|eq, ":cur_month", 6),
          (this_or_next|eq, ":cur_month", 9),
          (eq, ":cur_month", 11),
          (assign, ":month_day_limit", 30),
        (else_try),
          (try_begin),
            (store_div, ":cur_year_div_4", ":cur_year", 4),
            (val_mul, ":cur_year_div_4", 4),
            (eq, ":cur_year_div_4", ":cur_year"),
            (assign, ":month_day_limit", 29),
          (else_try),
            (assign, ":month_day_limit", 28),
          (try_end),
        (try_end),
        (try_begin),
          (gt, ":cur_day", ":month_day_limit"),
          (val_sub, ":cur_day", ":month_day_limit"),
          (val_add, ":cur_month", 1),
          (try_begin),
            (gt, ":cur_month", 12),
            (val_sub, ":cur_month", 12),
            (val_add, ":cur_year", 1),
          (try_end),
        (else_try),
          (assign, ":try_range", 0),
        (try_end),
      (try_end),
      (assign, reg1, ":cur_day"),
      (assign, reg2, ":cur_year"),
      (try_begin),
        (eq, ":cur_month", 1),
        (str_store_string, s1, "str_january_reg1_reg2"),
      (else_try),
        (eq, ":cur_month", 2),
        (str_store_string, s1, "str_february_reg1_reg2"),
      (else_try),
        (eq, ":cur_month", 3),
        (str_store_string, s1, "str_march_reg1_reg2"),
      (else_try),
        (eq, ":cur_month", 4),
        (str_store_string, s1, "str_april_reg1_reg2"),
      (else_try),
        (eq, ":cur_month", 5),
        (str_store_string, s1, "str_may_reg1_reg2"),
      (else_try),
        (eq, ":cur_month", 6),
        (str_store_string, s1, "str_june_reg1_reg2"),
      (else_try),
        (eq, ":cur_month", 7),
        (str_store_string, s1, "str_july_reg1_reg2"),
      (else_try),
        (eq, ":cur_month", 8),
        (str_store_string, s1, "str_august_reg1_reg2"),
      (else_try),
        (eq, ":cur_month", 9),
        (str_store_string, s1, "str_september_reg1_reg2"),
      (else_try),
        (eq, ":cur_month", 10),
        (str_store_string, s1, "str_october_reg1_reg2"),
      (else_try),
        (eq, ":cur_month", 11),
        (str_store_string, s1, "str_november_reg1_reg2"),
      (else_try),
        (eq, ":cur_month", 12),
        (str_store_string, s1, "str_december_reg1_reg2"),
      (try_end),
      (set_result_string, s1),
  ]),
  
  #script_game_get_money_text:
  # This script is called from the game engine when an amount of money needs to be displayed.
  # INPUT: arg1 = amount in units
  # OUTPUT: result string = money in text
("game_get_money_text",
    [
      (store_script_param_1, ":amount"),
      (try_begin),
        (eq, ":amount", 1),
        (str_store_string, s1, "str_1_denar"),
      (else_try),
        (assign, reg1, ":amount"),
        (str_store_string, s1, "str_reg1_denars"),
      (try_end),
      (set_result_string, s1),
  ]),
  
  #script_game_get_party_companion_limit:
  # This script is called from the game engine when the companion limit is needed for a party.
  # INPUT: arg1 = none
  # OUTPUT: reg0 = companion_limit
("game_get_party_companion_limit",
    [
      (assign, ":troop_no", "trp_player"),
      
      (assign, ":limit", 10),
      (store_skill_level, ":skill", "skl_leadership", ":troop_no"),
      (store_attribute_level, ":charisma", ":troop_no", ca_charisma),
      (val_mul, ":skill", 10),
      (val_add, ":limit", ":skill"),
      (val_add, ":limit", ":charisma"),
      
      (troop_get_slot, ":troop_renown", ":troop_no", slot_troop_renown),
      (store_div, ":renown_bonus", ":troop_renown", 25),
      (val_add, ":limit", ":renown_bonus"),
      
      (assign, reg0, ":limit"),
      (set_trigger_result, reg0),
  ]),
  
  # script_party_get_ideal_size @used for NPC parties.
  # Input: arg1 = party_no
  # Output: reg0: ideal size
("party_get_ideal_size",
    [
      (store_script_param_1, ":party_no"),
      (assign, ":limit", 30),
      (try_begin),
        (party_slot_eq, ":party_no", slot_party_type, spt_kingdom_hero_party),
        (party_stack_get_troop_id, ":party_leader", ":party_no", 0),
        (store_faction_of_party, ":faction_id", ":party_no"),
        (assign, ":limit", 10),
        
        (store_skill_level, ":skill", "skl_leadership", ":party_leader"),
        (store_attribute_level, ":charisma", ":party_leader", ca_charisma),
        (val_mul, ":skill", 3),
        (val_add, ":limit", ":skill"),
        (val_add, ":limit", ":charisma"),
        
        (troop_get_slot, ":troop_renown", ":party_leader", slot_troop_renown),
        (store_div, ":renown_bonus", ":troop_renown", 25),
        (val_add, ":limit", ":renown_bonus"),
        
        (try_begin),
          (faction_slot_eq, ":faction_id", slot_faction_leader, ":party_leader"),
          (val_add, ":limit", 50),
        (try_end),
      (try_end),
      (assign, reg0, ":limit"),
  ]),
  
  
  #script_game_get_party_prisoner_limit:
  # This script is called from the game engine when the prisoner limit is needed for a party.
  # INPUT: arg1 = party_no
  # OUTPUT: reg0 = prisoner_limit
("game_get_party_prisoner_limit",
    [
      #      (store_script_param_1, ":party_no"),
      (assign, ":troop_no", "trp_player"),
      
      (assign, ":limit", 0),
      (store_skill_level, ":skill", "skl_prisoner_management", ":troop_no"),
      (store_mul, ":limit", ":skill", 5),
      (assign, reg0, ":limit"),
      (set_trigger_result, reg0),
  ]),
  
  #script_game_get_item_extra_text:
  # This script is called from the game engine when an item's properties are displayed.
  # INPUT: arg1 = item_no, arg2 = extra_text_id (this can be between 0-7 (7 included))
  # OUTPUT: result_string = item extra text, trigger_result = text color (0 for default)
("game_get_item_extra_text",
    [
      (store_script_param, ":item_no", 1),
      (store_script_param, ":extra_text_id", 2),
      (try_begin),
        (is_between, ":item_no", morale_boosters_begin, morale_boosters_end),
        (try_begin),
          (eq, ":extra_text_id", 0),
          (item_get_slot, ":food_bonus", ":item_no", slot_item_food_bonus),
          (assign, reg1, ":food_bonus"),
          (set_result_string, "@+{reg1} to party morale"),
          (set_trigger_result, 0x4444FF),
        (try_end),
      (try_end),
	  ### Add stuff about books here
  ]),
  
  #script_game_on_disembark:
  # This script is called from the game engine when the player reaches the shore with a ship.
  # INPUT: pos0 = disembark position
  # OUTPUT: none
("game_on_disembark",
	[
		#(jump_to_menu, "mnu_disembark"),
		]
	),
  
  
  #script_game_context_menu_get_buttons:
  # This script is called from the game engine when the player clicks the right mouse button over a party on the map.
  # INPUT: arg1 = party_no
  # OUTPUT: none, fills the menu buttons
("game_context_menu_get_buttons",
    [(store_script_param, ":party_no", 1),
      (try_begin),
        (neq, ":party_no", "p_main_party"),
        (context_menu_add_item, "@Move here", cmenu_move),
      (try_end),
      #(try_begin),
      #  (is_between, ":party_no", cities_begin, cities_end),
      #  (context_menu_add_item, "@View notes", 1),
      #(else_try),
      #  (party_get_num_companion_stacks, ":num_stacks", ":party_no"),
      #  (gt, ":num_stacks", 0),
      #  (party_stack_get_troop_id, ":troop_no", ":party_no", 0),
      #  (is_between, ":troop_no", kingdom_heroes_begin, kingdom_heroes_end),
      # (context_menu_add_item, "@View notes", 2),
      #(try_end),
  ]),
  
  #script_game_event_context_menu_button_clicked:
  # This script is called from the game engine when the player clicks on a button at the right mouse menu.
  # INPUT: arg1 = party_no, arg2 = button_value
  # OUTPUT: none
("game_event_context_menu_button_clicked",
    [(store_script_param, ":party_no", 1),
      (store_script_param, ":button_value", 2),
      (try_begin),
        (eq, ":button_value", 1),
        (change_screen_notes, 3, ":party_no"),
      (else_try),
        (eq, ":button_value", 2),
        (party_stack_get_troop_id, ":troop_no", ":party_no", 0),
        (change_screen_notes, 1, ":troop_no"),
      (try_end),
  ]),
  
  
  # npc_get_troop_wage
  # This script is called from module system to calculate troop wages for npc parties.
  # Input:
  # param1: troop_id
  # Output: reg0: weekly wage
  
("npc_get_troop_wage",
    [
      (store_script_param_1, ":troop_id"),
      (assign,":wage", 0),
      (try_begin),
        (troop_is_hero, ":troop_id"),
      (else_try),
        (store_character_level, ":wage", ":troop_id"),
        (val_mul, ":wage", ":wage"),
        (val_add, ":wage", 25),
        (val_div, ":wage", 20),
      (try_end),
      (assign, reg0, ":wage"),
  ]),
  
  #script_setup_talk_info
  # INPUT:
  # param1: item_id
  # param2: production_rate (should be between -100 (for net consumption) and 100 (for net production)
("setup_talk_info",
    [
      (talk_info_set_relation_bar, "$g_talk_troop_relation"),
      (str_store_troop_name, s61, "$g_talk_troop"),
      (str_store_string, s61, "@ {s1}"),
      (assign, reg1, "$g_talk_troop_relation"),
      (str_store_string, s62, "str_relation_reg1"),
      (talk_info_set_line, 0, s61),
      (talk_info_set_line, 1, s62),
      (call_script, "script_describe_relation_to_s63", "$g_talk_troop_relation"),
      (talk_info_set_line, 3, s63),
  ]),
  
  #script_update_party_creation_random_limits
  # INPUT: none
("update_party_creation_random_limits",
    [
      (store_character_level, ":player_level", "trp_player"),
      (store_mul, ":upper_limit", ":player_level", 4),
      (val_add, ":upper_limit", 35),
      (val_min, ":upper_limit", 100),
      (set_party_creation_random_limits, 0, ":upper_limit"),
      (assign, reg0, ":upper_limit"),
  ]),
  
  
  #script_center_set_trade_good_production
  # INPUT:
  # param1: center_no
  # param2: item_id
  # param3: production_rate (should be between -100 (for net consumption) and 100 (for net production)
("center_set_trade_good_production",
    [
      (store_script_param, ":center_no", 1),
      (store_script_param, ":item_no", 2),
      (store_script_param, ":production_rate", 3),
      (val_sub, ":item_no", trade_goods_begin),
      (val_add, ":item_no", slot_town_trade_good_productions_begin),
      (party_set_slot, ":center_no", ":item_no", ":production_rate"),
  ]),
  

  
  #script_update_trade_good_prices
  # INPUT: none
("update_trade_good_prices",
    [
		(try_for_range, ":center_no", cities_begin, cities_end),
	        (this_or_next|is_between, ":center_no", towns_begin, towns_end),
	        (is_between, ":center_no", villages_begin, villages_end),
	        (call_script, "script_update_trade_good_price_for_party", ":center_no"),
		(try_end),
		]
	),
  
  #script_update_trade_good_price_for_party
  # INPUT: arg1 = party_no
  ("update_trade_good_price_for_party",
    [
      (store_script_param, ":center_no", 1),
      (try_for_range, ":cur_good", trade_goods_begin, trade_goods_end),
        (store_sub, ":cur_good_slot", ":cur_good", trade_goods_begin),
        (val_add, ":cur_good_slot", slot_town_trade_good_productions_begin),
        (store_sub, ":cur_good_price_slot", ":cur_good", trade_goods_begin),
        (val_add, ":cur_good_price_slot", slot_town_trade_good_prices_begin),
        (party_get_slot, ":production", ":center_no", ":cur_good_slot"),
        (party_get_slot, ":cur_price", ":center_no", ":cur_good_price_slot"),
        (try_begin),
          (lt, ":production", 0), #demand is greater than supply
          (store_mul, ":change_factor", ":production", -3), #price will be increased by his factor
        (else_try),
          (store_mul, ":change_factor", ":production", 2), #price will be decreased by this factor
        (try_end),
        (val_mul, ":change_factor", 2),
        (store_random_in_range, ":random_change", 0, ":change_factor"),
        (try_begin),
          (lt, ":production", 0), #demand is greater than supply
          (val_add, ":cur_price", ":random_change"),
        (else_try),
          (val_sub, ":cur_price", ":random_change"),
        (try_end),
        #Move price towards average by 2%...
        (store_sub, ":price_difference", ":cur_price", average_price_factor),
        (val_mul, ":price_difference", 98),
        (val_div, ":price_difference", 100),
        (store_add, ":new_price", average_price_factor, ":price_difference"),
        (val_clamp, ":new_price", minimum_price_factor, maximum_price_factor),
        (party_set_slot, ":center_no", ":cur_good_price_slot", ":new_price"),
      (try_end),
  ]),
  
  #script_do_merchant_town_trade
  # INPUT: arg1 = party_no (of the merchant), arg2 = center_no
  ("do_merchant_town_trade",
    [
      (store_script_param_1, ":party_no"),
      (store_script_param_2, ":center_no"),
      (call_script, "script_do_party_center_trade", ":party_no", ":center_no", 20), #change prices by 20%
      
      (assign, ":total_change", reg0),
      #Adding the earnings to the wealth (maximum changed price is the earning)
      (val_div, ":total_change", 2),
      (str_store_party_name, s1, ":party_no"),
      (str_store_party_name, s2, ":center_no"),
      (assign, reg1, ":total_change"),
      (try_begin),
        (eq, "$cheat_mode", 1),
        (display_message, "@Merchant {s1} traded with {s2} and earned {reg1} denars."),
      (try_end),
      
      #Adding tax revenue to the center
      (party_get_slot, ":accumulated_tariffs", ":center_no", slot_town_accumulated_tariffs),
      (val_div, ":total_change", 3), #33% of the merchant's revenue.
      (val_add, ":accumulated_tariffs", ":total_change"),
      (party_set_slot, ":center_no", slot_town_accumulated_tariffs, ":accumulated_tariffs"),
      
      ##      #Giving a constant wage to the party
      ##      (party_get_num_companions, ":party_size", ":party_no"),
      ##      (store_mul, ":party_wage", ":party_size", 5),
      ##      (val_sub, ":cur_wealth", ":party_wage"),
      ##      #Hiring new troops if wealth is above a limit
      ##      (try_begin),
      ##        (gt, ":cur_wealth", 2500),
      ##        (val_mul, ":party_wage", 30),
      ##        (gt, ":cur_wealth", ":party_wage"),
      ##        (party_add_template, ":party_no", "pt_merchant_party_reinforcement"),
      ##        (party_get_num_companions, ":party_new_size", ":party_no"),
      ##        (val_sub, ":party_new_size", ":party_size"),
      ##        (val_mul, ":party_new_size", 10),
      ##        (val_sub, ":cur_wealth", ":party_new_size"),
      ##      (try_end),
      ##      (val_max, ":cur_wealth", 2000),
      ##      (troop_set_slot, ":troop_no", slot_troop_wealth, ":cur_wealth"),
  ]),
  
  #script_party_calculate_regular_strength:
  # INPUT:
  # param1: Party-id
  ("party_calculate_regular_strength",
    [
      (store_script_param_1, ":party"), #Party_id
      
      (assign, reg0,0),
      (party_get_num_companion_stacks, ":num_stacks",":party"),
      (try_for_range, ":i_stack", 0, ":num_stacks"),
        (party_stack_get_troop_id, ":stack_troop",":party",":i_stack"),
        (neg|troop_is_hero, ":stack_troop"),
        (store_character_level, ":stack_strength", ":stack_troop"),
        (val_add, ":stack_strength", 12),
        (val_mul, ":stack_strength", ":stack_strength"),
        (val_div, ":stack_strength", 100),
        (party_stack_get_size, ":stack_size",":party",":i_stack"),
        (party_stack_get_num_wounded, ":num_wounded",":party",":i_stack"),
        (val_sub, ":stack_size", ":num_wounded"),
        (val_mul, ":stack_strength", ":stack_size"),
        (val_add,reg0, ":stack_strength"),
      (try_end),
  ]),
  
  
  
  
  #script_party_calculate_strength:
  # INPUT: arg1 = party_id
  # OUTPUT: reg0 = strength
  
  ("party_calculate_strength",
    [
      (store_script_param_1, ":party"), #Party_id
      
      (assign, reg0,0),
      (party_get_num_companion_stacks, ":num_stacks",":party"),
      (try_for_range, ":i_stack", 0, ":num_stacks"),
        (party_stack_get_troop_id, ":stack_troop",":party",":i_stack"),
		(try_begin),
	        (neg|troop_is_hero, ":stack_troop"),
	        (store_character_level, ":stack_strength", ":stack_troop"),
	        (val_add, ":stack_strength", 12),
	        (val_mul, ":stack_strength", ":stack_strength"),
	        (val_div, ":stack_strength", 100),
	        (party_stack_get_size, ":stack_size",":party",":i_stack"),
	        (party_stack_get_num_wounded, ":num_wounded",":party",":i_stack"),
	        (val_sub, ":stack_size", ":num_wounded"),
	        (val_mul, ":stack_strength", ":stack_size"),
	        (val_add,reg0, ":stack_strength"),
		(else_try),
			(troop_is_hero, ":stack_troop"),
			(store_character_level, ":stack_strength", ":stack_troop"),
	        (val_add, ":stack_strength", 12),
	        (val_mul, ":stack_strength", ":stack_strength"),
	        (val_div, ":stack_strength", 100),
	        (val_add,reg0,":stack_strength"),
		(try_end),
      (try_end),
  ]),
  
  #script_party_calculate_loot:
  # INPUT:
  # param1: Party-id
  # Returns num looted items in reg0
  
("party_calculate_loot",
	[
		(store_script_param_1, ":enemy_party"), #Enemy Party_id


		(call_script, "script_calculate_main_party_shares"),
		(assign, ":num_player_party_shares", reg0),
		#      (assign, ":num_ally_shares", reg1),
		#      (store_add, ":num_shares",  ":num_player_party_shares", ":num_ally_shares"),

		#Calculate player loot probability
		#      (assign, ":loot_probability", 100),
		#      (val_mul, ":loot_probability", 10),
		#      (val_div, ":loot_probability", ":num_shares"),

		(assign, ":loot_probability", 10),
		(val_mul, ":loot_probability", "$g_strength_contribution_of_player"),
		(val_div, ":loot_probability", ":num_player_party_shares"),
		(assign,':loot_probability',1000),
		(try_for_range, ":i_loot", 0, num_party_loot_slots),
			(store_add, ":cur_loot_slot", ":i_loot", slot_party_looted_item_1),
			(party_get_slot, ":item_no", "$g_enemy_party", ":cur_loot_slot"),
			(gt, ":item_no", 0),
			(party_set_slot, "$g_enemy_party", ":cur_loot_slot", 0),
			(val_sub, ":cur_loot_slot", slot_party_looted_item_1),
			(val_add, ":cur_loot_slot", slot_party_looted_item_1_modifier),
			(party_get_slot, ":item_modifier", "$g_enemy_party", ":cur_loot_slot"),
			(troop_add_item, "trp_temp_troop", ":item_no", ":item_modifier"),
		(try_end),
		(party_set_slot, "$g_enemy_party", slot_party_next_looted_item_slot, 0),

		#Now loot the defeated party
		(party_get_num_companion_stacks, ":num_stacks",":enemy_party"),
		(try_for_range, ":i_stack", 0, ":num_stacks"),
			(party_stack_get_troop_id,     ":stack_troop",":enemy_party",":i_stack"),
			(neg|troop_is_hero, ":stack_troop"),
			(party_stack_get_size, ":stack_size",":enemy_party",":i_stack"),
			(try_for_range, ":unused", 0, ":stack_size"),
				(troop_loot_troop,"trp_temp_troop",":stack_troop",":loot_probability"),
			(try_end),
		(try_end),
		# get rid of all the useless clothes
		(troop_get_inventory_capacity,':inv_cap','trp_temp_troop'),
		(try_for_range,':i_slot',0,':inv_cap'),
			(troop_get_inventory_slot,':item_id','trp_temp_troop',':i_slot'),
			(is_between,':item_id','itm_waraji_a','itm_shino_suneate'),
			(troop_remove_item,'trp_temp_troop',':item_id'),
		(try_end),
		# sort the loot by price
		# count number of looted items
		(assign, ":num_looted_items",0),
		(troop_get_inventory_capacity, ":inv_cap", "trp_temp_troop"),
		(try_for_range, ":i_slot", 0, ":inv_cap"),
			(troop_get_inventory_slot, ":item_id", "trp_temp_troop", ":i_slot"),
			(ge, ":item_id", 0),
			(val_add, ":num_looted_items",1),
		(try_end),
		# add koban or strings of coins and food
		(try_begin),
			(eq,'$g_encountered_party_template','pt_river_pirates'),
			(store_random_in_range,':num_strings',2,6),
			(troop_add_items,'trp_temp_troop','itm_string_of_coins',':num_strings'),
			(store_random_in_range,':num_food',2,6),
			(try_for_range,':unused',0,':num_food'),
				(store_random_in_range,':food_item_no',food_begin,food_end),
				(troop_add_items,'trp_temp_troop',':food_item_no',1),
			(try_end),
		(else_try),
			(eq,'$g_encountered_party_template','pt_bandits'),
			(store_random_in_range,':num_strings',4,8),
			(troop_add_items,'trp_temp_troop','itm_string_of_coins',':num_strings'),
			(store_random_in_range,':num_food',2,6),
			(try_for_range,':unused',0,':num_food'),
				(store_random_in_range,':food_item_no',food_begin,food_end),
				(troop_add_items,'trp_temp_troop',':food_item_no',1),
			(try_end),
		(else_try),
			(eq,'$g_encountered_party_template','pt_forest_bandits'),
			(store_random_in_range,':num_strings',5,12),
			(troop_add_items,'trp_temp_troop','itm_string_of_coins',':num_strings'),
			(store_random_in_range,':num_food',2,6),
			(try_for_range,':unused',0,':num_food'),
				(store_random_in_range,':food_item_no',food_begin,food_end),
				(troop_add_items,'trp_temp_troop',':food_item_no',1),
			(try_end),
		(else_try),
			(this_or_next|eq,'$g_encountered_party_template','pt_mountain_bandits'),
			(eq,'$g_encountered_party_template','pt_sea_raiders'),
			(store_random_in_range,':num_strings',7,15),
			(troop_add_items,'trp_temp_troop','itm_string_of_coins',':num_strings'),
			(store_random_in_range,':num_strings',2,5),
			(troop_add_items,'trp_temp_troop','itm_koban',':num_strings'),
			(store_random_in_range,':num_food',2,6),
			(try_for_range,':unused',0,':num_food'),
				(store_random_in_range,':food_item_no',food_begin,food_end),
				(troop_add_items,'trp_temp_troop',':food_item_no',1),
			(try_end),
		(else_try),
			(this_or_next|eq,'$g_encountered_party_template','pt_hosokawa_patrol'),
			(eq,'$g_encountered_party_template','pt_yamana_patrol'),
			(store_random_in_range,':num_strings',9,21),
			(troop_add_items,'trp_temp_troop','itm_string_of_coins',':num_strings'),
			(store_random_in_range,':num_strings',3,8),
			(troop_add_items,'trp_temp_troop','itm_koban',':num_strings'),
			(store_random_in_range,':num_food',2,6),
			(try_for_range,':unused',0,':num_food'),
				(store_random_in_range,':food_item_no',food_begin,food_end),
				(troop_add_items,'trp_temp_troop',':food_item_no',1),
			(try_end),
		(else_try),
			(eq,'$g_encountered_party_template','pt_local_patrol'),
			(store_random_in_range,':num_strings',12,25),
			(troop_add_items,'trp_temp_troop','itm_string_of_coins',':num_strings'),
			(store_random_in_range,':num_food',2,6),
			(try_for_range,':unused',0,':num_food'),
				(store_random_in_range,':food_item_no',food_begin,food_end),
				(troop_add_items,'trp_temp_troop',':food_item_no',1),
			(try_end),
		(try_end),
		#add horses
		(try_begin),
			(gt,'$g_mission_remaining_horses',0),
			(assign,reg10,'$g_mission_remaining_horses'),
			(display_message,'@Remaining horses: {reg10}',debug_text),
			(try_for_range,':unused',0,'$g_mission_remaining_horses'),
				(store_random_in_range,':horse_item_no','itm_draft_horse','itm_fast_riding_horse'),
				(call_script,'script_item_get_random_imod',itp_type_horse),
				(assign,':imod',reg0),
				(troop_add_item,'trp_temp_troop',':horse_item_no',':imod'),
			(try_end),
			(assign,'$g_mission_remaining_horses',0),
		(try_end),
		
		(try_begin),
			(party_slot_eq, "$g_enemy_party", slot_party_type, spt_kingdom_caravan),
			(assign, ":plunder_amount", 10),
			(val_mul, ":plunder_amount", "$g_strength_contribution_of_player"),
			(val_div, ":plunder_amount", 40),
			#       (val_div, ":plunder_amount", ":num_player_party_shares"),
			(val_clamp, ":plunder_amount", 1, 50),
			(store_sub, ":item_to_price_slot", slot_town_trade_good_prices_begin, trade_goods_begin),
			(reset_item_probabilities,100),
			(try_for_range, ":cur_goods", trade_goods_begin, trade_goods_end),
				(store_add, ":cur_price_slot", ":cur_goods", ":item_to_price_slot"),
				(party_get_slot, ":cur_price", "$g_enemy_party", ":cur_price_slot"),
				(assign, ":cur_probability", 100),
				(val_mul, ":cur_probability", average_price_factor),
				(val_div, ":cur_probability", ":cur_price"),
				(set_item_probability_in_merchandise,":cur_goods",":cur_probability"),
			(try_end),
			(troop_add_merchandise,"trp_temp_troop",itp_type_goods,":plunder_amount"),
			(val_add, ":num_looted_items", ":plunder_amount"),
		(try_end),
		(call_script,'script_sort_inventory','trp_temp_troop'),
		(assign, reg0, ":num_looted_items"),
		]),
  
  #script_calculate_main_party_shares:
  # INPUT:
  # Returns number of player party shares in reg0
  
  ("calculate_main_party_shares",
    [
      (party_get_num_companions,":num_player_party_shares",'p_main_party'),
	  (val_add,":num_player_party_shares",5),
	  (val_mul,":num_player_party_shares",2),
      # Add shares for player's party
      #(party_get_num_companion_stacks, ":num_stacks","p_main_party"),
      #(try_for_range, ":i_stack", 1, ":num_stacks"),
      #  (party_stack_get_troop_id,     ":stack_troop","p_main_party",":i_stack"),
      #  (try_begin),
      #    (neg|troop_is_hero, ":stack_troop"),
      #    (party_stack_get_size, ":stack_size","p_main_party",":i_stack"),
      #    (val_add, ":num_player_party_shares", ":stack_size"),
      #  (else_try),
      #    (val_add, ":num_player_party_shares", 5),
      #  (try_end),
      #(try_end),
      
      (assign, reg0, ":num_player_party_shares"),
  ]),
  
  #script_party_give_xp_and_gold:
  # INPUT:
  # param1: destroyed Party-id
  # calculates and gives player paty's share of gold and xp.
  
  ("party_give_xp_and_gold",
    [
      (store_script_param_1, ":enemy_party"), #Party_id
      
      (call_script, "script_calculate_main_party_shares"),
      (assign, ":num_player_party_shares", reg0),
      
      #      (assign, ":num_ally_shares", reg1),
      #     (store_add, ":num_total_shares",  ":num_player_party_shares", ":num_ally_shares"),
      
      (assign, ":total_gain", 0),
      (party_get_num_companion_stacks, ":num_stacks",":enemy_party"),
      (try_for_range, ":i_stack", 0, ":num_stacks"),
        (party_stack_get_troop_id,     ":stack_troop",":enemy_party",":i_stack"),
        (neg|troop_is_hero, ":stack_troop"),
        (party_stack_get_size, ":stack_size",":enemy_party",":i_stack"),
        (store_character_level, ":level", ":stack_troop"),
        (store_add, ":gain", ":level", 10),
        (val_mul, ":gain", ":gain"),
        (val_div, ":gain", 10),
        (store_mul, ":stack_gain", ":gain", ":stack_size"),
        (val_add, ":total_gain", ":stack_gain"),
      (try_end),
      
      (val_mul, ":total_gain", "$g_strength_contribution_of_player"),
      (val_div, ":total_gain", 100),
      
      (val_min, ":total_gain", 40000), #eliminate negative results
      
      
      #      (store_mul, ":player_party_xp_gain", ":total_gain", ":num_player_party_shares"),
      #      (val_div, ":player_party_xp_gain", ":num_total_shares"),
      
      (assign, ":player_party_xp_gain", ":total_gain"),
      
      (store_random_in_range, ":r", 50, 100),
      (val_mul, ":player_party_xp_gain", ":r"),
      (val_div, ":player_party_xp_gain", 100),
      
      (party_add_xp, "p_main_party", ":player_party_xp_gain"),
      
      (store_mul, ":player_gold_gain", ":total_gain", 5),
      (val_min, ":player_gold_gain", 60000), #eliminate negative results
      (store_random_in_range, ":r", 50, 100),
      (val_mul, ":player_gold_gain", ":r"),
      (val_div, ":player_gold_gain", 100),
      (val_div, ":player_gold_gain", ":num_player_party_shares"),
      
      #add gold now
      (party_get_num_companion_stacks, ":num_stacks","p_main_party"),
      (try_for_range, ":i_stack", 0, ":num_stacks"),
        (party_stack_get_troop_id,     ":stack_troop","p_main_party",":i_stack"),
        (try_begin),
          (troop_is_hero, ":stack_troop"),
          (troop_add_gold, ":stack_troop", ":player_gold_gain"),
        (try_end),
      (try_end),
      
      #Add morale
      (assign, ":morale_gain", ":total_gain"),
      (val_div, ":morale_gain", ":num_player_party_shares"),
      (call_script, "script_change_player_party_morale", ":morale_gain"),
  ]),
  
  
  #script_setup_troop_meeting:
  # INPUT:
  # param1: troop_id with which meeting will be made.
  # param2: troop_dna (optional)
  
  ("setup_troop_meeting",
    [
      (store_script_param_1, ":meeting_troop"),
      (store_script_param_2, ":troop_dna"),
      (modify_visitors_at_site,"scn_conversation_scene"),(reset_visitors),
      (set_visitor,0,"trp_player"),
      #       (party_stack_get_troop_dna,":troop_dna",":meeting_party",0),
      (set_visitor,17,":meeting_troop",":troop_dna"),
      (set_jump_mission,"mt_conversation_encounter"),
      (jump_to_scene,"scn_conversation_scene"),
      (change_screen_map_conversation, ":meeting_troop"),
  ]),
  
  #script_setup_party_meeting:
  # INPUT:
  # param1: Party-id with which meeting will be made.
  
  ("setup_party_meeting",
    [
      (store_script_param_1, ":meeting_party"),
      (modify_visitors_at_site,"scn_conversation_scene"),
	  (reset_visitors),
      (set_visitor,0,"trp_player"),
      (party_stack_get_troop_id, ":meeting_troop",":meeting_party",0),
      (party_stack_get_troop_dna,":troop_dna",":meeting_party",0),
      (set_visitor,17,":meeting_troop",":troop_dna"),
      (set_jump_mission,"mt_conversation_encounter"),
      (jump_to_scene,"scn_conversation_scene"),
      (change_screen_map_conversation, ":meeting_troop"),
  ]),
  
  #script_party_remove_all_companions:
  # INPUT:
  # param1: Party-id from which  companions will be removed.
  # "$g_move_heroes" : controls if heroes will also be removed.
  
  ("party_remove_all_companions",
    [
      (store_script_param_1, ":party"), #Source Party_id
      (party_get_num_companion_stacks, ":num_companion_stacks",":party"),
      (try_for_range_backwards, ":stack_no", 0, ":num_companion_stacks"),
        (party_stack_get_troop_id,   ":stack_troop",":party",":stack_no"),
        (this_or_next|neg|troop_is_hero, ":stack_troop"),
        (eq, "$g_move_heroes", 1),
        (party_stack_get_size,  ":stack_size",":party",":stack_no"),
        (party_remove_members, ":party", ":stack_troop",  ":stack_size"),
      (try_end),
  ]),
  
  #script_party_remove_all_prisoners:
  # INPUT:
  # param1: Party-id from which  prisoners will be removed.
  # "$g_move_heroes" : controls if heroes will also be removed.
  
  ("party_remove_all_prisoners",
    [
      (store_script_param_1, ":party"), #Source Party_id
      (party_get_num_prisoner_stacks, ":num_prisoner_stacks",":party"),
      (try_for_range_backwards, ":stack_no", 0, ":num_prisoner_stacks"),
        (party_prisoner_stack_get_troop_id,   ":stack_troop",":party",":stack_no"),
        (this_or_next|neg|troop_is_hero, ":stack_troop"),
        (eq, "$g_move_heroes", 1),
        (party_prisoner_stack_get_size, ":stack_size",":party",":stack_no"),
        (party_remove_prisoners, ":party", ":stack_troop", ":stack_size"),
      (try_end),
  ]),
  
  #script_party_add_party_companions:
  # INPUT:
  # param1: Party-id to add the second part
  # param2: Party-id which will be added to the first one.
  # "$g_move_heroes" : controls if heroes will also be added.
  
  ("party_add_party_companions",
    [
      (store_script_param_1, ":target_party"), #Target Party_id
      (store_script_param_2, ":source_party"), #Source Party_id
      (party_get_num_companion_stacks, ":num_stacks",":source_party"),
      (try_for_range, ":stack_no", 0, ":num_stacks"),
        (party_stack_get_troop_id,     ":stack_troop",":source_party",":stack_no"),
        (this_or_next|neg|troop_is_hero, ":stack_troop"),
        (eq, "$g_move_heroes", 1),
        (party_stack_get_size,         ":stack_size",":source_party",":stack_no"),
        (party_add_members, ":target_party", ":stack_troop", ":stack_size"),
        (party_stack_get_num_wounded, ":num_wounded", ":source_party", ":stack_no"),
        (party_wound_members, ":target_party", ":stack_troop", ":num_wounded"),
      (try_end),
  ]),
  
  #script_party_add_party_prisoners:
  # INPUT:
  # param1: Party-id to add the second party
  # param2: Party-id which will be added to the first one.
  # "$g_move_heroes" : controls if heroes will also be added.
  
  ("party_add_party_prisoners",
    [
      (store_script_param_1, ":target_party"), #Target Party_id
      (store_script_param_2, ":source_party"), #Source Party_id
      (party_get_num_prisoner_stacks, ":num_stacks",":source_party"),
      (try_for_range, ":stack_no", 0, ":num_stacks"),
        (party_prisoner_stack_get_troop_id,     ":stack_troop",":source_party",":stack_no"),
        (this_or_next|neg|troop_is_hero, ":stack_troop"),
        (eq, "$g_move_heroes", 1),
        (party_prisoner_stack_get_size,         ":stack_size",":source_party",":stack_no"),
        (party_add_members, ":target_party", ":stack_troop", ":stack_size"),
      (try_end),
  ]),
  
  #script_party_prisoners_add_party_companions:
  # INPUT:
  # param1: Party-id to add the second part
  # param2: Party-id which will be added to the first one.
  # "$g_move_heroes" : controls if heroes will also be added.
  
  ("party_prisoners_add_party_companions",
    [
      (store_script_param_1, ":target_party"), #Target Party_id
      (store_script_param_2, ":source_party"), #Source Party_id
      (party_get_num_companion_stacks, ":num_stacks",":source_party"),
      (try_for_range, ":stack_no", 0, ":num_stacks"),
        (party_stack_get_troop_id,     ":stack_troop",":source_party",":stack_no"),
        (this_or_next|neg|troop_is_hero, ":stack_troop"),
        (eq, "$g_move_heroes", 1),
        (party_stack_get_size, ":stack_size",":source_party",":stack_no"),
        (party_add_prisoners, ":target_party", ":stack_troop", ":stack_size"),
      (try_end),
  ]),
  
  #script_party_prisoners_add_party_prisoners:
  # INPUT:
  # param1: Party-id to add the second part
  # param2: Party-id which will be added to the first one.
  # "$g_move_heroes" : controls if heroes will also be added.
  
  ("party_prisoners_add_party_prisoners",
    [
      (store_script_param_1, ":target_party"), #Target Party_id
      (store_script_param_2, ":source_party"), #Source Party_id
      (party_get_num_prisoner_stacks, ":num_stacks",":source_party"),
      (try_for_range, ":stack_no", 0, ":num_stacks"),
        (party_prisoner_stack_get_troop_id,     ":stack_troop",":source_party",":stack_no"),
        (this_or_next|neg|troop_is_hero, ":stack_troop"),
        (eq, "$g_move_heroes", 1),
        (party_prisoner_stack_get_size,         ":stack_size",":source_party",":stack_no"),
        (party_add_prisoners, ":target_party", ":stack_troop", ":stack_size"),
      (try_end),
  ]),
  
  # script_party_add_party:
  # INPUT:
  # param1: Party-id to add the second part
  # param2: Party-id which will be added to the first one.
  # "$g_move_heroes" : controls if heroes will also be added.
  
  ("party_add_party",
    [
      (store_script_param_1, ":target_party"), #Target Party_id
      (store_script_param_2, ":source_party"), #Source Party_id
      (call_script, "script_party_add_party_companions",          ":target_party", ":source_party"),
      (call_script, "script_party_prisoners_add_party_prisoners", ":target_party", ":source_party"),
  ]),
  
  
  #script_party_copy:
  # INPUT:
  # param1: Party-id to copy the second party
  # param2: Party-id which will be copied to the first one.
  
  ("party_copy",
    [
      (assign, "$g_move_heroes", 1),
      (store_script_param_1, ":target_party"), #Target Party_id
      (store_script_param_2, ":source_party"), #Source Party_id
      (party_clear, ":target_party"),
      (call_script, "script_party_add_party", ":target_party", ":source_party"),
  ]),
  
  
  #script_clear_party_group:
  # INPUT:
  # param1: Party-id of the root of the group.
  # This script will clear the root party and all parties attached to it recursively.
  
  ("clear_party_group",
    [
      (store_script_param_1, ":root_party"),
      (party_clear, ":root_party"),
      (party_get_num_attached_parties, ":num_attached_parties", ":root_party"),
      (try_for_range, ":attached_party_rank", 0, ":num_attached_parties"),
        (party_get_attached_party_with_rank, ":attached_party", ":root_party", ":attached_party_rank"),
        (call_script, "script_clear_party_group", ":attached_party"),
      (try_end),
  ]),
  
  #script_get_nonempty_party_in_group:
  # INPUT:
  # param1: Party-id of the root of the group.
  # OUTPUT: reg0: nonempy party-id
  
  ("get_nonempty_party_in_group",
    [
      
      (store_script_param_1, ":party_no"),
      (party_get_num_companions, ":num_companions", ":party_no"),
      (try_begin),
        (gt, ":num_companions", 0),
        (assign, reg0, ":party_no"),
      (else_try),
        (assign, reg0, -1),
        
        (party_get_num_attached_parties, ":num_attached_parties", ":party_no"),
        (try_for_range, ":attached_party_rank", 0, ":num_attached_parties"),
          (lt, reg0, 0),
          (party_get_attached_party_with_rank, ":attached_party", ":party_no", ":attached_party_rank"),
          (call_script, "script_get_nonempty_party_in_group", ":attached_party"),
        (try_end),
      (try_end),
  ]),
  
  #script_collect_prisoners_from_empty_parties:
  # INPUT:
  # param1: Party-id of the root of the group.
  # param2: Party to collect prisoners in.
  # make sure collection party is cleared before calling this.
  
  ("collect_prisoners_from_empty_parties",
    [
      (store_script_param_1, ":party_no"),
      (store_script_param_2, ":collection_party"),
      
      (party_get_num_companions, ":num_companions", ":party_no"),
      (try_begin),
        (eq, ":num_companions", 0), #party is empty (has no companions). Collect its prisoners.
        (party_get_num_prisoner_stacks, ":num_stacks",":party_no"),
        (try_for_range, ":stack_no", 0, ":num_stacks"),
          (party_prisoner_stack_get_troop_id,     ":stack_troop",":party_no",":stack_no"),
          (troop_is_hero, ":stack_troop"),
          (party_add_members, ":collection_party", ":stack_troop", 1),
        (try_end),
      (try_end),
      (party_get_num_attached_parties, ":num_attached_parties", ":party_no"),
      (try_for_range, ":attached_party_rank", 0, ":num_attached_parties"),
        (party_get_attached_party_with_rank, ":attached_party", ":party_no", ":attached_party_rank"),
        (call_script, "script_collect_prisoners_from_empty_parties", ":attached_party", ":collection_party"),
      (try_end),
  ]),
  
  
  
  #script_print_casualties_to_s0:
  # INPUT:
  # param1: Party_id, param2: 0 = use new line, 1 = use comma
  
  #OUTPUT:
  # string register 0.
  
  ("print_casualties_to_s0",
    [(store_script_param, ":party_no", 1),
      (store_script_param, ":use_comma", 2),
      (str_clear, s0),
      (assign, ":total_reported", 0),
      (assign, ":total_wounded", 0),
      (assign, ":total_killed", 0),
      (party_get_num_companion_stacks, ":num_stacks",":party_no"),
      (try_for_range, ":i_stack", 0, ":num_stacks"),
        (party_stack_get_troop_id, ":stack_troop",":party_no",":i_stack"),
        (party_stack_get_size, ":stack_size",":party_no",":i_stack"),
        (party_stack_get_num_wounded, ":num_wounded",":party_no",":i_stack"),
        (store_sub, ":num_killed", ":stack_size", ":num_wounded"),
        (val_add, ":total_killed", ":num_killed"),
        (val_add, ":total_wounded", ":num_wounded"),
        (try_begin),
          (this_or_next|gt, ":num_killed", 0),
          (gt, ":num_wounded", 0),
          (str_store_troop_name_by_count, s1, ":stack_troop"),
          (store_add, reg3, ":num_killed", ":num_wounded"),
          (try_begin),
            (troop_is_hero, ":stack_troop"),
            (assign, reg3, 0),
          (try_end),
          (try_begin),
            (gt, ":num_killed", 0),
            (gt, ":num_wounded", 0),
            (assign, reg4, ":num_killed"),
            (assign, reg5, ":num_wounded"),
            (str_store_string, s2, "@{reg4} killed, {reg5} wounded"),
          (else_try),
            (gt, ":num_killed", 0),
            (str_store_string, s2, "@killed"),
          (else_try),
            (str_store_string, s2, "@wounded"),
          (try_end),
          (try_begin),
            (eq, ":use_comma", 1),
            (try_begin),
              (eq, ":total_reported", 0),
              (str_store_string, s0, "@{reg3?{reg3}:} {s1} ({s2})"),
            (else_try),
              (str_store_string, s0, "@{s0}, {reg3?{reg3}:} {s1} ({s2})"),
            (try_end),
          (else_try),
            (str_store_string, s0, "@{s0}^{reg3?{reg3}:} {s1} ({s2})"),
          (try_end),
          (val_add, ":total_reported", 1),
        (try_end),
      (try_end),
      
      (try_begin),
        (this_or_next|gt, ":total_killed", 0),
        (gt, ":total_wounded", 0),
        (store_add, reg3, ":total_killed", ":total_wounded"),
        (try_begin),
          (gt, ":total_killed", 0),
          (gt, ":total_wounded", 0),
          (assign, reg4, ":total_killed"),
          (assign, reg5, ":total_wounded"),
          (str_store_string, s2, "@{reg4} killed, {reg5} wounded"),
        (else_try),
          (gt, ":total_killed", 0),
          (str_store_string, s2, "@killed"),
        (else_try),
          (str_store_string, s2, "@wounded"),
        (try_end),
        (str_store_string, s0, "@{s0}^TOTAL: {reg3} ({s2})"),
      (else_try),
        (try_begin),
          (eq, ":use_comma", 1),
          (str_store_string, s0, "@None"),
        (else_try),
          (str_store_string, s0, "@^None"),
        (try_end),
      (try_end),
  ]),
  
  
  #script_party_count_fit_regulars:
  # Returns the number of unwounded regular companions in a party
  # INPUT:
  # param1: Party-id
  
  ("party_count_fit_regulars",
    [
      (store_script_param_1, ":party"), #Party_id
      (party_get_num_companion_stacks, ":num_stacks",":party"),
      (assign, reg0, 0),
      (try_for_range, ":i_stack", 0, ":num_stacks"),
        (party_stack_get_troop_id,     ":stack_troop",":party",":i_stack"),
        (neg|troop_is_hero, ":stack_troop"),
        (party_stack_get_size,         ":stack_size",":party",":i_stack"),
        (party_stack_get_num_wounded, ":num_wounded",":party",":i_stack"),
        (val_sub, ":stack_size", ":num_wounded"),
        (val_add, reg0, ":stack_size"),
      (try_end),
  ]),
  
  
  #script_party_count_fit_for_battle:
  # Returns the number of unwounded regular companions in a party
  # INPUT:
  # param1: Party-id
  # OUTPUT: reg0 = result
  ("party_count_fit_for_battle",
    [
      (store_script_param_1, ":party"), #Party_id
      (party_get_num_companion_stacks, ":num_stacks",":party"),
      (assign, reg0, 0),
      (try_for_range, ":i_stack", 0, ":num_stacks"),
        (party_stack_get_troop_id,     ":stack_troop",":party",":i_stack"),
        (assign, ":num_fit",0),
        (try_begin),
          (troop_is_hero, ":stack_troop"),
          #          (store_troop_health, ":troop_hp", ":stack_troop"),
          (try_begin),
            (neg|troop_is_wounded, ":stack_troop"),
            #            (ge,  ":troop_hp", 20),
            (assign, ":num_fit",1),
          (try_end),
        (else_try),
          (party_stack_get_size,         ":num_fit",":party",":i_stack"),
          (party_stack_get_num_wounded, ":num_wounded",":party",":i_stack"),
          (val_sub, ":num_fit", ":num_wounded"),
        (try_end),
        (val_add, reg0, ":num_fit"),
      (try_end),
  ]),
  
  #script_party_count_prisoners:
  # Returns the number of prisoners in a party
  # INPUT:
  # param1: Party-id
  
  ("party_count_prisoners",
    [
      (store_script_param_1, ":party"), #Party_id
      (party_get_num_prisoner_stacks, ":num_stacks",":party"),
      (assign, reg0, 0),
      (try_for_range, ":i_stack", 0, ":num_stacks"),
        (party_prisoner_stack_get_size,         ":stack_size",":party",":i_stack"),
        (val_add, reg0, ":stack_size"),
      (try_end),
  ]),
  
  #script_get_stack_with_rank:
  # Returns the stack no, containing unwounded regular companions with rank rank.
  # INPUT:
  # param1: Party-id
  # param2: rank
  
  ("get_stack_with_rank",
    [
      (store_script_param_1, ":party"), #Party_id
      (store_script_param_2, ":rank"), #Rank
      (party_get_num_companion_stacks, ":num_stacks",":party"),
      (assign, reg0, -1),
      (assign, ":num_total", 0),
      (try_for_range, ":i_stack", 0, ":num_stacks"),
        (eq, reg0, -1), #continue only if we haven't found the result yet.
        (party_stack_get_troop_id,     ":stack_troop",":party",":i_stack"),
        (neg|troop_is_hero, ":stack_troop"),
        (party_stack_get_size,         ":stack_size",":party",":i_stack"),
        (party_stack_get_num_wounded,  ":num_wounded",":party",":i_stack"),
        (val_sub, ":stack_size", ":num_wounded"),
        (val_add, ":num_total", ":stack_size"),
        (try_begin),
          (lt, ":rank", ":num_total"),
          (assign, reg0, ":i_stack"),
        (try_end),
      (try_end),
  ]),
  
  
  
  #OUTPUT:
  # This script doesn't return a value but populates the parties p_temp_wounded and p_temp_killed with the wounded and killed.
  #Example:
  #  (script_inflict_casualties_to_party, "_p_main_party" ,50),
  #  Simulate 50 rounds of casualties to main_party.
  
  ("inflict_casualties_to_party",
    [
      (party_clear, "p_temp_casualties"),
      (store_script_param_1, ":party"), #Party_id
      (call_script, "script_party_count_fit_regulars", ":party"),
      (assign, ":num_fit", reg0), #reg(47) = number of fit regulars.
      (store_script_param_2, ":num_attack_rounds"), #number of attacks
      (try_for_range, ":unused", 0, ":num_attack_rounds"),
        (gt, ":num_fit", 0),
        (store_random_in_range, ":attacked_troop_rank", 0 , ":num_fit"), #attack troop with rank reg(46)
        (assign, reg1, ":attacked_troop_rank"),
        (call_script, "script_get_stack_with_rank", ":party", ":attacked_troop_rank"),
        (assign, ":attacked_stack", reg0), #reg(53) = stack no to attack.
        #        (display_message,"str_debug_reg0"),
        (party_stack_get_troop_id,     ":attacked_troop",":party",":attacked_stack"),
        (store_character_level, ":troop_toughness", ":attacked_troop"),
        (val_add, ":troop_toughness", 5),  #troop-toughness = level + 5
        (assign, ":casualty_chance", 10000),
        (val_div, ":casualty_chance", ":troop_toughness"), #dying chance
        (try_begin),
          (store_random_in_range, ":rand_num", 0 ,10000),
          (lt, ":rand_num", ":casualty_chance"), #check chance to be a casualty
          (store_random_in_range, ":rand_num2", 0, 2), #check if this troop will be wounded or killed
          (try_begin),
            (troop_is_hero,":attacked_troop"), #currently troop can't be a hero, but no harm in keeping this.
            (store_troop_health, ":troop_hp",":attacked_troop"),
            (val_sub, ":troop_hp", 45),
            (val_max, ":troop_hp", 1),
            (troop_set_health, ":attacked_troop", ":troop_hp"),
          (else_try),
            (lt, ":rand_num2", 1), #wounded
            (party_add_members, "p_temp_casualties", ":attacked_troop", 1),
            (party_wound_members, "p_temp_casualties", ":attacked_troop", 1),
            (party_wound_members, ":party", ":attacked_troop", 1),
          (else_try), #killed
            (party_add_members, "p_temp_casualties", ":attacked_troop", 1),
            (party_remove_members, ":party", ":attacked_troop", 1),
          (try_end),
          (val_sub, ":num_fit", 1), #adjust number of fit regulars.
        (try_end),
      (try_end),
  ]),
  
  
  #script_move_members_with_ratio:
  # INPUT:
  # param1: Source Party-id
  # param2: Target Party-id
  # pin_number = ratio of members to move, multiplied by 1000
  
  #OUTPUT:
  # This script doesn't return a value but moves some of the members of source party to target party according to the given ratio.
  ("move_members_with_ratio",
    [
      (store_script_param_1, ":source_party"), #Source Party_id
      (store_script_param_2, ":target_party"), #Target Party_id
      (party_get_num_prisoner_stacks, ":num_stacks",":source_party"),
      (try_for_range_backwards, ":stack_no", 0, ":num_stacks"),
        (party_prisoner_stack_get_troop_id,     ":stack_troop",":source_party",":stack_no"),
        (party_prisoner_stack_get_size,    ":stack_size",":source_party",":stack_no"),
        (store_mul, ":number_to_move",":stack_size","$pin_number"),
        (val_div, ":number_to_move", 1000),
        (party_remove_prisoners, ":source_party", ":stack_troop", ":number_to_move"),
        (assign, ":number_moved", reg0),
        (party_add_prisoners, ":target_party", ":stack_troop", ":number_moved"),
      (try_end),
      (party_get_num_companion_stacks, ":num_stacks",":source_party"),
      (try_for_range_backwards, ":stack_no", 0, ":num_stacks"),
        (party_stack_get_troop_id,     ":stack_troop",":source_party",":stack_no"),
        (party_stack_get_size,    ":stack_size",":source_party",":stack_no"),
        (store_mul, ":number_to_move",":stack_size","$pin_number"),
        (val_div, ":number_to_move", 1000),
        (party_remove_members, ":source_party", ":stack_troop", ":number_to_move"),
        (assign, ":number_moved", reg0),
        (party_add_members, ":target_party", ":stack_troop", ":number_moved"),
      (try_end),
  ]),
  
  
  # script_count_parties_of_faction_and_party_type:
  # counts number of active parties with a template and faction.
  # Input: arg1 = faction_no, arg2 = party_type
  # Output: reg0 = count
  
  ("count_parties_of_faction_and_party_type",
    [
      (store_script_param_1, ":faction_no"),
      (store_script_param_2, ":party_type"),
      (assign, reg0, 0),
      (try_for_parties, ":party_no"),
        (party_is_active, ":party_no"),
        (party_get_slot, ":cur_party_type", ":party_no", slot_party_type),
        (store_faction_of_party, ":cur_faction", ":party_no"),
        (eq, ":cur_party_type", ":party_type"),
        (eq, ":cur_faction", ":faction_no"),
        (val_add, reg0, 1),
      (try_end),
  ]),
  
  
  
  # script_faction_calculate_strength - substitute my code
  # Input: arg1 = faction_no
  # Output: reg0 = strength
  ("faction_strength",
    [
      (store_script_param,':faction',1),
	  (store_script_param,':opt',2),
      (try_begin),
        (eq,':opt',0),
        (assign,':num_cities',0),
        (assign,':num_towns',0),
        (assign,':num_villages',0),
        (assign,':num_forts',0),
        (assign,':num_parties',0),
        (assign,':num_allies',0),
        # (assign,':faction_str',0),
        (try_for_range,':city',cities_begin,cities_end), # count all cities allied to :faction
          (store_faction_of_party,':fac',':city'),
          (try_begin),
            (call_script,'script_cf_faction_enemies',':faction',':fac'),
          (else_try),
            (val_add,':num_cities',1),
          (try_end),
        (try_end),
        (try_for_range,':town',towns_begin,towns_end), # count all towns allied to :faction
          (store_faction_of_party,':fac',':town'),
          (try_begin),
            (call_script,'script_cf_faction_enemies',':faction',':fac'),
          (else_try),
            (val_add,':num_towns',1),
          (try_end),
        (try_end),
        (try_for_range,':village',villages_begin,villages_end), # count all villages allied to :faction
          (store_faction_of_party,':fac',':village'),
          (try_begin),
            (call_script,'script_cf_faction_enemies',':faction',':fac'),
          (else_try),
            (val_add,':num_villages',1),
          (try_end),
        (try_end),
        (try_for_parties,':fort'), # count all forts belonging to :faction
          (party_get_template_id,':template',':fort'),
          (eq,':template','pt_fort'),
          (store_faction_of_party,':fac',':fort'),
          (try_begin),
            (call_script,'script_cf_faction_enemies',':faction',':fac'),
          (else_try),
            (val_add,':num_forts',1),
          (try_end),
        (try_end),
        (try_for_parties,':party'), # count all parties belonging to or allied to :faction
          (store_faction_of_party,':fac',':party'),
          (try_begin),
            (call_script,'script_cf_faction_enemies',':faction',':fac'),
          (else_try),
            (val_add,':num_parties',1),
          (try_end),
        (try_end),
        (try_for_range,':fac','fac_hosokawa','fac_end_fac'), # count all allies of :faction
          (try_begin),
            (call_script,'script_cf_faction_enemies',':faction',':fac'),
          (else_try),
            (val_add,':num_allies',1),
          (try_end),
        (try_end),
        # values: allies are worth 100, cities 50, towns 25, villages 10, forts 15, parties 2
        # sum all
        (val_mul,':num_allies',100),
        (val_mul,':num_cities',50),
        (val_mul,':num_towns',25),
        (val_mul,':num_villages',10),
        (val_mul,':num_forts',15),
        (val_mul,':num_parties',2),
        (store_add,':sum',':num_allies',':num_cities'),
        (val_add,':sum',':num_towns'),
        (val_add,':sum',':num_villages'),
        (val_add,':sum',':num_forts'),
        (val_add,':sum',':num_parties'),
        # normalization formula: score = 1000 + (raw-avg)*1000/avg, avg = (raw+1000)/2
        (store_add,':avg',':sum',1000),
        (val_div,':avg',2),
        (store_add,':diff',':sum',':avg'),
        (val_mul,':diff',1000),
        (val_div,':diff',':avg'),
        (store_add,':score',1000,':diff'),
        (faction_set_slot,':faction',slot_faction_strength,':score'),
        (str_store_faction_name,21,':faction'),
        (assign,reg21,':score'),
        (display_message,'str_fac_str'),
      (try_end),
    ]
  ),
  
  
  #OUTPUT:
  # This script may return false if there is no matching town.
  # reg0 = town_no (Can fail)
  ("cf_select_random_center_with_faction",
    [
      (store_script_param_1, ":faction_no"),
      (assign, ":result", -1),
      # First count num matching spawn points
      (assign, ":no_centers", 0),
      (try_for_range,":cur_center", cities_begin, cities_end),
        (store_faction_of_party, ":cur_faction", ":cur_center"),
        (eq, ":cur_faction", ":faction_no"),
        (val_add, ":no_centers", 1),
      (try_end),
      (gt, ":no_centers", 0), #Fail if there are no centers
      (store_random_in_range, ":random_center", 0, ":no_centers"),
      (assign, ":no_centers", 0),
      (try_for_range,":cur_center", cities_begin, cities_end),
        (eq, ":result", -1),
        (store_faction_of_party, ":cur_faction", ":cur_center"),
        (eq, ":cur_faction", ":faction_no"),
        (val_add, ":no_centers", 1),
        (gt, ":no_centers", ":random_center"),
        (assign, ":result", ":cur_center"),
      (try_end),
      (assign, reg0, ":result"),
  ]),
  
  #script_cf_select_random_town_at_peace_with_faction:
  # This script selects a random town in range [towns_begin, towns_end)
  # such that faction of the town is friendly to given_faction
  # INPUT:
  # arg1 = faction_no
  
  #OUTPUT:
  # This script may return false if there is no matching town.
  # reg0 = town_no
  ("cf_select_random_town_at_peace_with_faction",
    [
      (store_script_param_1, ":faction_no"),
      (assign, ":result", -1),
      # First count num matching towns
      (assign, ":no_towns", 0),
      (try_for_range,":cur_town", towns_begin, towns_end),
        (store_faction_of_party, ":cur_faction", ":cur_town"),
        (store_relation,":reln", ":cur_faction", ":faction_no"),
        (ge, ":reln", 0),
        (val_add, ":no_towns", 1),
      (try_end),
      (gt, ":no_towns", 0), #Fail if there are no towns
      (store_random_in_range, ":random_town", 0, ":no_towns"),
      (assign, ":no_towns", 0),
      (try_for_range,":cur_town", towns_begin, towns_end),
        (eq, ":result", -1),
        (store_faction_of_party, ":cur_faction", ":cur_town"),
        (store_relation,":reln", ":cur_faction", ":faction_no"),
        (ge, ":reln", 0),
        (val_add, ":no_towns", 1),
        (gt, ":no_towns", ":random_town"),
        (assign, ":result", ":cur_town"),
      (try_end),
      (assign, reg0, ":result"),
  ]),
  
  
  # script_shuffle_scene_slots:
  # Shuffles a range of slots of a given troop.
  # Used for exploiting a troop as an array.
  # Input: $pin_troop, arg1 = slot_begin, arg2 = slot_end
  ("shuffle_troop_slots",
    [
      (store_script_param, ":slots_begin",1),
      (store_script_param, ":slots_end",2),
	  (store_script_param,':pin_troop',3),
      (try_for_range, ":cur_slot_no", ":slots_begin", ":slots_end"),
        (store_random_in_range, ":random_slot_no", ":slots_begin", ":slots_end"), #reg(58) = random slot. Now exchange slots reg(57) and reg(58)
        (troop_get_slot, ":cur_slot_value", ":pin_troop", ":cur_slot_no"), #temporarily store the value in slot reg(57) in reg(59)
        (troop_get_slot, ":random_slot_value", ":pin_troop", ":random_slot_no"), #temporarily store the value in slot reg(58) in reg(60)
        (troop_set_slot, ":pin_troop", ":cur_slot_no", ":random_slot_value"), # Now exchange the two...
        (troop_set_slot, ":pin_troop", ":random_slot_no", ":cur_slot_value"),
      (try_end),
  ]),
  
  # script_cf_faction_get_random_enemy_faction
  # Input: arg1 = faction_no
  # Output: reg0 = faction_no (Can fail)
  ("cf_faction_get_random_enemy_faction",
    [
      (store_script_param_1, ":faction_no"),
      
      (assign, ":result", -1),
      (assign, ":count_factions", 0),
      (try_for_range, ":cur_faction", factions_begin, factions_end),
        (store_relation, ":cur_relation", ":faction_no", ":cur_faction"),
        (le, ":cur_relation", -1),
        (val_add, ":count_factions", 1),
      (try_end),
      (store_random_in_range,":random_faction",0,":count_factions"),
      (assign, ":count_factions", 0),
      (try_for_range, ":cur_faction", factions_begin, factions_end),
        (eq, ":result", -1),
        (store_relation, ":cur_relation", ":faction_no", ":cur_faction"),
        (le, ":cur_relation", -1),
        (val_add, ":count_factions", 1),
        (gt, ":count_factions", ":random_faction"),
        (assign, ":result", ":cur_faction"),
      (try_end),
      
      (neq, ":result", -1),
      (assign, reg0, ":result"),
  ]),
  
  
  # script_cf_troop_get_random_enemy_troop_with_occupation
  # Input: arg1 = troop_no,
  # Output: reg0 = enemy_troop_no (Can fail)
  ("cf_troop_get_random_enemy_troop_with_occupation",
    [
      (store_script_param_1, ":troop_no"),
      (store_script_param_2, ":occupation"),
      
      (assign, ":result", -1),
      (assign, ":count_enemies", 0),
      (try_for_range, ":cur_slot", slot_troop_enemies_begin, slot_troop_enemies_end),
        (troop_get_slot, ":cur_enemy", ":troop_no", ":cur_slot"),
        (gt, ":cur_enemy", 0),
        (troop_slot_eq, ":cur_enemy", slot_troop_occupation, ":occupation"),
        (val_add, ":count_enemies", 1),
      (try_end),
      (store_random_in_range,":random_enemy",0,":count_enemies"),
      (assign, ":count_enemies", 0),
      (try_for_range, ":cur_slot", slot_troop_enemies_begin, slot_troop_enemies_end),
        (eq, ":result", -1),
        (troop_get_slot, ":cur_enemy", ":troop_no", ":cur_slot"),
        (gt, ":cur_enemy", 0),
        (troop_slot_eq, ":cur_enemy", slot_troop_occupation, ":occupation"),
        (val_add, ":count_enemies", 1),
        (gt, ":count_enemies", ":random_enemy"),
        (assign, ":result", ":cur_enemy"),
      (try_end),
      
      (neq, ":result", -1),
      (assign, reg0, ":result"),
  ]),
  
  
  ##  # script_cf_troop_get_random_enemy_troop_as_a_town_lord
  ##  # Input: arg1 = troop_no
  ##  # Output: reg0 = enemy_troop_no (Can fail)
  ##  ("cf_troop_get_random_enemy_troop_as_a_town_lord",
  ##    [
  ##      (store_script_param_1, ":troop_no"),
  ##
  ##      (assign, ":result", -1),
  ##      (assign, ":count_enemies", 0),
  ##      (try_for_range, ":cur_slot", slot_troop_enemies_begin, slot_troop_enemies_end),
  ##        (troop_get_slot, ":cur_enemy", ":troop_no", ":cur_slot"),
  ##        (gt, ":cur_enemy", 0),
  ##        (troop_slot_eq, ":cur_enemy", slot_troop_occupation, slto_kingdom_hero),
  ##        (call_script, "script_get_number_of_hero_centers", ":cur_enemy"),
  ##        (gt, reg0, 0),
  ##        (val_add, ":count_enemies", 1),
  ##      (try_end),
  ##      (store_random_in_range,":random_enemy",0,":count_enemies"),
  ##      (assign, ":count_enemies", 0),
  ##      (try_for_range, ":cur_slot", slot_troop_enemies_begin, slot_troop_enemies_end),
  ##        (eq, ":result", -1),
  ##        (troop_get_slot, ":cur_enemy", ":troop_no", ":cur_slot"),
  ##        (gt, ":cur_enemy", 0),
  ##        (troop_slot_eq, ":cur_enemy", slot_troop_occupation, slto_kingdom_hero),
  ##        (call_script, "script_get_number_of_hero_centers", ":cur_enemy"),
  ##        (gt, reg0, 0),
  ##        (val_add, ":count_enemies", 1),
  ##        (gt, ":count_enemies", ":random_enemy"),
  ##        (assign, ":result", ":cur_enemy"),
  ##      (try_end),
  ##      (neq, ":result", -1),
  ##      (assign, reg0, ":result"),
  ##  ]),
    
  
  ##  # script_cf_get_random_kingdom_hero
  ##  # Input: arg1 = faction_no
  ##  # Output: reg0 = troop_no (Can fail)
  ##  ("cf_get_random_kingdom_hero",
  ##    [
  ##      (store_script_param_1, ":faction_no"),
  ##      (assign, ":count_heroes", 0),
  ##      (try_for_range, ":center_no", cities_begin, cities_end),
  ##        (store_faction_of_party, ":cur_faction", ":center_no"),
  ##        (eq, ":cur_faction", ":faction_no"),
  ##        (party_get_slot, ":cur_lord", ":center_no", slot_town_lord),
  ##        (is_between, ":cur_lord", heroes_begin, heroes_end),
  ##        (val_add, ":count_heroes", 1),
  ##      (try_end),
  ##      (store_random_in_range, ":random_hero", 0, ":count_heroes"),
  ##      (assign, ":result", -1),
  ##      (assign, ":count_heroes", 0),
  ##      (try_for_range, ":center_no", cities_begin, cities_end),
  ##        (eq, ":result", -1),
  ##        (store_faction_of_party, ":cur_faction", ":center_no"),
  ##        (eq, ":cur_faction", ":faction_no"),
  ##        (party_get_slot, ":cur_lord", ":center_no", slot_town_lord),
  ##        (is_between, ":cur_lord", heroes_begin, heroes_end),
  ##        (val_add, ":count_heroes", 1),
  ##        (lt, ":random_hero", ":count_heroes"),
  ##        (assign, ":result", ":cur_lord"),
  ##      (try_end),
  ##      (neq, ":result", -1),
  ##      (assign, reg0, ":result"),
  ##  ]),
  
  
  # script_cf_get_random_kingdom_hero_as_lover
  # Input: arg1 = troop_no (of the lady)
  # Output: reg0 = troop_no (of the hero) (Can fail)
  
  
  
  ##  # script_cf_get_random_siege_location_with_faction
  ##  # Input: arg1 = faction_no
  ##  # Output: reg0 = center_no, Can Fail!
  ##  ("cf_get_random_siege_location_with_faction",
  ##    [
  ##      (store_script_param_1, ":faction_no"),
  ##      (assign, ":result", -1),
  ##      (assign, ":count_sieges", 0),
  ##      (try_for_range, ":center_no", walled_cities_begin, walled_cities_end),
  ##        (party_get_battle_opponent, ":besieger_party", ":center_no"),
  ##        (gt, ":besieger_party", 0),
  ##        (store_faction_of_party, ":cur_faction_no", ":center_no"),
  ##        (eq, ":cur_faction_no", ":faction_no"),
  ##        (val_add, ":count_sieges", 1),
  ##      (try_end),
  ##      (store_random_in_range,":random_center",0,":count_sieges"),
  ##      (assign, ":count_sieges", 0),
  ##      (try_for_range, ":center_no", walled_cities_begin, walled_cities_end),
  ##        (eq, ":result", -1),
  ##        (party_get_battle_opponent, ":besieger_party", ":center_no"),
  ##        (gt, ":besieger_party", 0),
  ##        (store_faction_of_party, ":cur_faction_no", ":center_no"),
  ##        (eq, ":cur_faction_no", ":faction_no"),
  ##        (val_add, ":count_sieges", 1),
  ##        (gt, ":count_sieges", ":random_center"),
  ##        (assign, ":result", ":center_no"),
  ##      (try_end),
  ##      (neq, ":result", -1),
  ##      (assign, reg0, ":result"),
  ##  ]),
  
  ##  # script_cf_get_random_siege_location_with_attacker_faction
  ##  # Input: arg1 = faction_no
  ##  # Output: reg0 = center_no, Can Fail!
  ##  ("cf_get_random_siege_location_with_attacker_faction",
  ##    [
  ##      (store_script_param_1, ":faction_no"),
  ##      (assign, ":result", -1),
  ##      (assign, ":count_sieges", 0),
  ##      (try_for_range, ":center_no", walled_cities_begin, walled_cities_end),
  ##        (party_get_battle_opponent, ":besieger_party", ":center_no"),
  ##        (gt, ":besieger_party", 0),
  ##        (store_faction_of_party, ":cur_faction_no", ":besieger_party"),
  ##        (eq, ":cur_faction_no", ":faction_no"),
  ##        (val_add, ":count_sieges", 1),
  ##      (try_end),
  ##      (store_random_in_range,":random_center",0,":count_sieges"),
  ##      (assign, ":count_sieges", 0),
  ##      (try_for_range, ":center_no", walled_cities_begin, walled_cities_end),
  ##        (eq, ":result", -1),
  ##        (party_get_battle_opponent, ":besieger_party", ":center_no"),
  ##        (gt, ":besieger_party", 0),
  ##        (store_faction_of_party, ":cur_faction_no", ":besieger_party"),
  ##        (eq, ":cur_faction_no", ":faction_no"),
  ##        (val_add, ":count_sieges", 1),
  ##        (gt, ":count_sieges", ":random_center"),
  ##        (assign, ":result", ":center_no"),
  ##      (try_end),
  ##      (neq, ":result", -1),
  ##      (assign, reg0, ":result"),
  ##  ]),
  
  
  
  ##  # script_cf_get_number_of_random_troops_from_party
  ##  # Input: arg1 = party_no, arg2 = number of troops to remove
  ##  # Output: reg0 = troop_no, Can fail if there are no slots having the required number of units!
  ##  ("cf_get_number_of_random_troops_from_party",
  ##    [
  ##      (store_script_param_1, ":party_no"),
  ##      (store_script_param_2, ":no_to_remove"),
  ##
  ##      (assign, ":result", -1),
  ##      (assign, ":count_stacks", 0),
  ##
  ##      (party_get_num_companion_stacks, ":num_stacks",":party_no"),
  ##      (try_for_range, ":i_stack", 0, ":num_stacks"),
  ##        (party_stack_get_size, ":stack_size",":party_no",":i_stack"),
  ##        (party_stack_get_num_wounded, ":num_wounded",":party_no",":i_stack"),
  ##        (val_sub, ":stack_size", ":num_wounded"),
  ##        (ge, ":stack_size", ":no_to_remove"),
  ##        (party_stack_get_troop_id, ":stack_troop",":party_no",":i_stack"),
  ##        (neg|troop_is_hero, ":stack_troop"),
  ##        (val_add, ":count_stacks", 1),
  ##      (try_end),
  ##      (store_random_in_range,":random_stack",0,":count_stacks"),
  ##      (assign, ":count_stacks", 0),
  ##      (try_for_range, ":i_stack", 0, ":num_stacks"),
  ##        (eq, ":result", -1),
  ##        (party_stack_get_size, ":stack_size",":party_no",":i_stack"),
  ##        (party_stack_get_num_wounded, ":num_wounded",":party_no",":i_stack"),
  ##        (val_sub, ":stack_size", ":num_wounded"),
  ##        (ge, ":stack_size", ":no_to_remove"),
  ##        (party_stack_get_troop_id, ":stack_troop",":party_no",":i_stack"),
  ##        (neg|troop_is_hero, ":stack_troop"),
  ##        (val_add, ":count_stacks", 1),
  ##        (gt, ":count_stacks", ":random_stack"),
  ##        (assign, ":result", ":stack_troop"),
  ##      (try_end),
  ##
  ##      (neq, ":result", -1),
  ##      (assign, reg0, ":result"),
  ##  ]),
  
  
  
  
  
  
  
  ##  # script_cf_get_random_enemy_lord_in_a_center
  ##  # Input: arg1 = faction_no
  ##  # Output: reg0 = troop_no, Can Fail!
  ##  ("cf_get_random_enemy_lord_in_a_center",
  ##    [
  ##      (store_script_param_1, ":faction_no"),
  ##      (assign, ":result", -1),
  ##      (assign, ":count_lords", 0),
  ##      (try_for_range, ":lord_no", heroes_begin, heroes_end),
  ##        (store_troop_faction, ":lord_faction_no", ":lord_no"),
  ##        (store_relation, ":lord_relation", ":lord_faction_no", ":faction_no"),
  ##        (le, ":lord_relation", -10),
  ##        (troop_slot_eq, ":lord_no", slot_troop_occupation, slto_kingdom_hero),
  ##        (troop_slot_eq, ":lord_no", slot_troop_is_prisoner, 0),
  ##        (troop_get_slot, ":lord_party", ":lord_no", slot_troop_leaded_party),
  ##        (ge, ":lord_party", 0),
  ##        (party_get_attached_to, ":lord_attachment", ":lord_party"),
  ##        (is_between, ":lord_attachment", cities_begin, cities_end), #is troop in a center?
  ##        (val_add, ":count_lords", 1),
  ##      (try_end),
  ##      (store_random_in_range, ":random_lord", 0, ":count_lords"),
  ##      (assign, ":count_lords", 0),
  ##      (try_for_range, ":lord_no", heroes_begin, heroes_end),
  ##        (eq, ":result", -1),
  ##        (store_troop_faction, ":lord_faction_no", ":lord_no"),
  ##        (store_relation, ":lord_relation", ":lord_faction_no", ":faction_no"),
  ##        (le, ":lord_relation", -10),
  ##        (troop_slot_eq, ":lord_no", slot_troop_occupation, slto_kingdom_hero),
  ##        (troop_slot_eq, ":lord_no", slot_troop_is_prisoner, 0),
  ##        (troop_get_slot, ":lord_party", ":lord_no", slot_troop_leaded_party),
  ##        (ge, ":lord_party", 0),
  ##        (party_get_attached_to, ":lord_attachment", ":lord_party"),
  ##        (is_between, ":lord_attachment", cities_begin, cities_end), #is troop in a center?
  ##        (val_add, ":count_lords", 1),
  ##        (lt, ":random_lord", ":count_lords"),
  ##        (assign, ":result", ":lord_no"),
  ##      (try_end),
  ##      (neq, ":result", -1),
  ##      (assign, reg0, ":result"),
  ##  ]),
  
  # script_get_closest_walled_center
  # Input: arg1 = party_no
  # Output: reg0 = center_no (closest)
  ("get_closest_walled_center",
    [
      (store_script_param_1, ":party_no"),
      (assign, ":min_distance", 9999999),
      (assign, reg0, -1),
      (try_for_range, ":center_no", cities_begin, cities_end),
        (store_distance_to_party_from_party, ":party_distance", ":party_no", ":center_no"),
        (lt, ":party_distance", ":min_distance"),
        (assign, ":min_distance", ":party_distance"),
        (assign, reg0, ":center_no"),
      (try_end),
  ]),
  
  # script_get_closest_center
  # Input: arg1 = party_no
  # Output: reg0 = center_no (closest)
  ("get_closest_center",
    [
      (store_script_param_1, ":party_no"),
      (assign, ":min_distance", 9999999),
      (assign, reg0, -1),
      (try_for_range, ":center_no", cities_begin, cities_end),
        (store_distance_to_party_from_party, ":party_distance", ":party_no", ":center_no"),
        (lt, ":party_distance", ":min_distance"),
        (assign, ":min_distance", ":party_distance"),
        (assign, reg0, ":center_no"),
      (try_end),
  ]),
  
  
  # script_get_closest_center_of_faction
  # Input: arg1 = party_no, arg2 = kingdom_no
  # Output: reg0 = center_no (closest)
  ("get_closest_center_of_faction",
    [
      (store_script_param_1, ":party_no"),
      (store_script_param_2, ":kingdom_no"),
      (assign, ":min_distance", 99999),
      (assign, ":result", -1),
      (try_for_range, ":center_no", cities_begin, cities_end),
        (store_faction_of_party, ":faction_no", ":center_no"),
        (eq, ":faction_no", ":kingdom_no"),
        (store_distance_to_party_from_party, ":party_distance", ":party_no", ":center_no"),
        (lt, ":party_distance", ":min_distance"),
        (assign, ":min_distance", ":party_distance"),
        (assign, ":result", ":center_no"),
      (try_end),
      (assign, reg0, ":result"),
  ]),
  
  # script_get_closest_walled_center_of_faction
  # Input: arg1 = party_no, arg2 = kingdom_no
  # Output: reg0 = center_no (closest)
  ("get_closest_walled_center_of_faction",
    [
      (store_script_param_1, ":party_no"),
      (store_script_param_2, ":kingdom_no"),
      (assign, ":min_distance", 99999),
      (assign, ":result", -1),
      (try_for_range, ":center_no", cities_begin, cities_end),
        (store_faction_of_party, ":faction_no", ":center_no"),
        (eq, ":faction_no", ":kingdom_no"),
        (store_distance_to_party_from_party, ":party_distance", ":party_no", ":center_no"),
        (lt, ":party_distance", ":min_distance"),
        (assign, ":min_distance", ":party_distance"),
        (assign, ":result", ":center_no"),
      (try_end),
      (assign, reg0, ":result"),
  ]),
  
  
  
  
  # script_let_nearby_parties_join_current_battle
  # Input: none
  # Output: none
("let_nearby_parties_join_current_battle",
    [
		(assign, ":enemy_party_no", "$g_encountered_party"),
		(try_for_parties, ":party_no"),
			(party_get_battle_opponent, ":opponent",":party_no"),
	        (lt, ":opponent", 0), #party is not itself involved in a battle
	        (party_get_attached_to, ":attached_to",":party_no"),
	        (lt, ":attached_to", 0), #party is not attached to another party
	        (get_party_ai_behavior, ":behavior", ":party_no"),
	        (neq, ":behavior", ai_bhvr_in_town),
	        (assign, ":join_distance", 5),
	        (try_begin),
				(is_currently_night),
				(assign, ":join_distance", 3),
	        (try_end),
	        (store_distance_to_party_from_party, ":distance", ":party_no", "p_main_party"),
	        (lt, ":distance", ":join_distance"),
	        (store_faction_of_party, ":faction_no", ":party_no"),
	        (store_faction_of_party, ":enemy_faction", ":enemy_party_no"),
			(party_get_template_id,':template',':party_no'),
			(store_relation, ":reln_with_enemy", ":faction_no", ":enemy_faction"),
	        (try_begin),
				(party_slot_lt,':party_no',slot_spawn_att_to_player,att_cautious),
				(gt, ":reln_with_enemy", 0),
				(neg|is_between,':template','pt_array','pt_end_objects'),
				(party_slot_neq,':party_no',slot_party_type,spt_traveler),
				(party_slot_neq,':party_no',slot_party_type,spt_merchant),
				(party_slot_neq,':party_no',slot_party_type,spt_village_farmer),
				(get_party_ai_behavior, ":ai_bhvr", ":party_no"),
				(neq, ":ai_bhvr", ai_bhvr_avoid_party),
				(party_quick_attach_to_current_battle, ":party_no", 1), #attach as enemy
				(str_store_party_name, s1, ":party_no"),
				(display_message, "str_s1_joined_battle_enemy"),
	        (else_try),
				(party_slot_ge,':party_no',slot_spawn_att_to_player,att_cautious),
				(lt, ":reln_with_enemy", 0),
				(neg|is_between,':template','pt_array','pt_end_objects'),
				(party_slot_neq,':party_no',slot_party_type,spt_traveler),
				(party_slot_neq,':party_no',slot_party_type,spt_merchant),
				(party_slot_neq,':party_no',slot_party_type,spt_village_farmer),
				(party_stack_get_troop_id, ":leader", ":party_no", 0),
				(troop_get_slot, ":player_relation", ":leader", slot_troop_player_relation),
				(ge, ":player_relation", 0),
				(party_quick_attach_to_current_battle, ":party_no", 0), #attach as friend
				(str_store_party_name, s1, ":party_no"),
				(display_message, "str_s1_joined_battle_friend"),
	        (try_end),
		(try_end),
		]
	),
  
  
  # script_party_wound_all_members_aux
  # Input: arg1 = party_no
  ("party_wound_all_members_aux",
    [
      (store_script_param_1, ":party_no"),
      
      (party_get_num_companion_stacks, ":num_stacks",":party_no"),
      (try_for_range, ":i_stack", 0, ":num_stacks"),
        (party_stack_get_troop_id, ":stack_troop",":party_no",":i_stack"),
        (try_begin),
          (neg|troop_is_hero, ":stack_troop"),
          (party_stack_get_size, ":stack_size",":party_no",":i_stack"),
          (party_wound_members, ":party_no", ":stack_troop", ":stack_size"),
        (else_try),
          (troop_set_health, ":stack_troop", 0),
        (try_end),
      (try_end),
      (party_get_num_attached_parties, ":num_attached_parties", ":party_no"),
      (try_for_range, ":attached_party_rank", 0, ":num_attached_parties"),
        (party_get_attached_party_with_rank, ":attached_party", ":party_no", ":attached_party_rank"),
        (call_script, "script_party_wound_all_members_aux", ":attached_party"),
      (try_end),
      
  ]),
  
  
  
  # script_party_wound_all_members
  # Input: arg1 = party_no
  ("party_wound_all_members",
    [
      (store_script_param_1, ":party_no"),
      
      (call_script, "script_party_wound_all_members_aux", ":party_no"),
  ]),
  
  
  
  # script_calculate_battle_advantage
  # Output: reg0 = battle advantage
  ("calculate_battle_advantage",
    [
      (call_script, "script_party_count_fit_for_battle", "p_collective_friends"),
      (assign, ":friend_count", reg0),
      
      (party_get_skill_level, ":player_party_tactics",  "p_main_party", skl_tactics),
      (party_get_skill_level, ":ally_party_tactics",  "p_collective_friends", skl_tactics),
      (val_max, ":player_party_tactics", ":ally_party_tactics"),
      
      (call_script, "script_party_count_fit_for_battle", "p_collective_enemy"),
      (assign, ":enemy_count", reg0),
      
      (party_get_skill_level, ":enemy_party_tactics",  "p_collective_enemy", skl_tactics),
      
      (val_add, ":friend_count", 1),
      (val_add, ":enemy_count", 1),
      
      (try_begin),
        (ge, ":friend_count", ":enemy_count"),
        (val_mul, ":friend_count", 100),
        (store_div, ":ratio", ":friend_count", ":enemy_count"),
        (store_sub, ":raw_advantage", ":ratio", 100),
      (else_try),
        (val_mul, ":enemy_count", 100),
        (store_div, ":ratio", ":enemy_count", ":friend_count"),
        (store_sub, ":raw_advantage", 100, ":ratio"),
      (try_end),
      
      (val_mul, ":player_party_tactics", 50),
      (val_mul, ":enemy_party_tactics", 50),
      (val_add, ":raw_advantage", ":player_party_tactics"),
      (val_sub, ":raw_advantage", ":enemy_party_tactics"),
      
      (val_mul, ":player_party_tactics", 30),
      (val_mul, ":enemy_party_tactics", 30),
      (val_add, ":raw_advantage", ":player_party_tactics"),
      (val_sub, ":raw_advantage", ":enemy_party_tactics"),
      (val_div, ":raw_advantage", 100),
      
      
      (assign, reg0, ":raw_advantage"),
      (display_message, "@Battle Advantage = {reg0}.", 0xFFFFFFFF),
  ]),
  
  
  # script_cf_check_enemies_nearby
  # Input: none
  # Output: none, fails when enemies are nearby
  ("cf_check_enemies_nearby",
    [
      (get_player_agent_no, ":player_agent"),
      (agent_is_alive, ":player_agent"),
      (try_begin),
        (agent_is_defender, ":player_agent"),
        (assign, ":player_defender", 1),
      (else_try),
        (assign, ":player_defender", 0),
      (try_end),
      (agent_get_position, pos1, ":player_agent"),
      (assign, ":result", 0),
      (try_for_agents,":cur_agent"),
        (neq, ":cur_agent", ":player_agent"),
        (agent_is_alive, ":cur_agent"),
        (agent_is_human, ":cur_agent"),
        (try_begin),
          (agent_is_defender, ":cur_agent"),
          (assign, ":agent_defender", 1),
        (else_try),
          (assign, ":agent_defender", 0),
        (try_end),
        (neq, ":player_defender", ":agent_defender"),
        (agent_get_position, pos2, ":cur_agent"),
        (get_distance_between_positions, ":cur_distance", pos1, pos2),
        (le, ":cur_distance", 1500),
        (assign, ":result", 1),
      (try_end),
      (eq, ":result", 0),
  ]),
  
  # script_get_heroes_attached_to_center_aux
  # For internal use only
  ("get_heroes_attached_to_center_aux",
    [
      (store_script_param_1, ":center_no"),
      (store_script_param_2, ":party_no_to_collect_heroes"),
      (party_get_num_companion_stacks, ":num_stacks",":center_no"),
      (try_for_range, ":i_stack", 0, ":num_stacks"),
        (party_stack_get_troop_id, ":stack_troop",":center_no",":i_stack"),
        (troop_is_hero, ":stack_troop"),
        (party_add_members, ":party_no_to_collect_heroes", ":stack_troop", 1),
      (try_end),
      (party_get_num_attached_parties, ":num_attached_parties", ":center_no"),
      (try_for_range, ":attached_party_rank", 0, ":num_attached_parties"),
        (party_get_attached_party_with_rank, ":attached_party", ":center_no", ":attached_party_rank"),
        (call_script, "script_get_heroes_attached_to_center_aux", ":attached_party", ":party_no_to_collect_heroes"),
      (try_end),
  ]),
  
  # script_get_heroes_attached_to_center
  # Input: arg1 = center_no, arg2 = party_no_to_collect_heroes
  # Output: none, adds heroes to the party_no_to_collect_heroes party
  ("get_heroes_attached_to_center",
    [
      (store_script_param_1, ":center_no"),
      (store_script_param_2, ":party_no_to_collect_heroes"),
      (party_clear, ":party_no_to_collect_heroes"),
      (call_script, "script_get_heroes_attached_to_center_aux", ":center_no", ":party_no_to_collect_heroes"),
  ]),
  
  
  # script_get_heroes_attached_to_center_as_prisoner_aux
  # For internal use only
  ("get_heroes_attached_to_center_as_prisoner_aux",
    [
      (store_script_param_1, ":center_no"),
      (store_script_param_2, ":party_no_to_collect_heroes"),
      (party_get_num_prisoner_stacks, ":num_stacks",":center_no"),
      (try_for_range, ":i_stack", 0, ":num_stacks"),
        (party_prisoner_stack_get_troop_id, ":stack_troop",":center_no",":i_stack"),
        (troop_is_hero, ":stack_troop"),
        (party_add_members, ":party_no_to_collect_heroes", ":stack_troop", 1),
      (try_end),
      (party_get_num_attached_parties, ":num_attached_parties", ":center_no"),
      (try_for_range, ":attached_party_rank", 0, ":num_attached_parties"),
        (party_get_attached_party_with_rank, ":attached_party", ":center_no", ":attached_party_rank"),
        (call_script, "script_get_heroes_attached_to_center_as_prisoner_aux", ":attached_party", ":party_no_to_collect_heroes"),
      (try_end),
  ]),
  
  
  # script_get_heroes_attached_to_center_as_prisoner
  # Input: arg1 = center_no, arg2 = party_no_to_collect_heroes
  # Output: none, adds heroes to the party_no_to_collect_heroes party
  ("get_heroes_attached_to_center_as_prisoner",
    [
      (store_script_param_1, ":center_no"),
      (store_script_param_2, ":party_no_to_collect_heroes"),
      (party_clear, ":party_no_to_collect_heroes"),
      (call_script, "script_get_heroes_attached_to_center_as_prisoner_aux", ":center_no", ":party_no_to_collect_heroes"),
  ]),
  
  
  
  # script_give_center_to_faction
  # Input: arg1 = center_no, arg2 = faction
  ("give_center_to_faction",
    [
      (store_script_param_1, ":center_no"),
      (store_script_param_2, ":faction_no"),
      (call_script, "script_give_center_to_faction_aux", ":center_no", ":faction_no"),
      (call_script, "script_update_village_market_towns"),
  ]),
  
  # script_give_center_to_faction_aux
  # Input: arg1 = center_no, arg2 = faction
  ("give_center_to_faction_aux",
    [
      (store_script_param_1, ":center_no"),
      (store_script_param_2, ":faction_no"),
      
      (party_set_faction, ":center_no", ":faction_no"),
      
      (party_set_slot, ":center_no", slot_town_lord, stl_unassigned),
      
      (try_begin),
        (party_set_banner_icon, ":center_no", 0),#Removing banner
      (try_end),
      
      (try_for_range, ":other_center", cities_begin, cities_end),
        (party_slot_eq, ":other_center", slot_village_bound_center, ":center_no"),
        (call_script, "script_give_center_to_faction_aux", ":other_center", ":faction_no"),
      (try_end),
  ]),

  
  # script_get_number_of_hero_centers
  # Input: arg1 = troop_no
  # Output: reg0 = number of centers that are ruled by the hero
  ("get_number_of_hero_centers",
    [
      (store_script_param_1, ":troop_no"),
      (assign, ":result", 0),
      (try_for_range, ":center_no", cities_begin, cities_end),
        (party_slot_eq, ":center_no", slot_town_lord, ":troop_no"),
        (val_add, ":result", 1),
      (try_end),
      (assign, reg0, ":result"),
  ]),
  
  
  
  
  
  
  # script_find_travel_location
  # Input: arg1 = center_no
  # Output: reg0 = new_center_no (to travel within the same faction)
  ("find_travel_location",
    [
      (store_script_param_1, ":center_no"),
      (store_faction_of_party, ":faction_no", ":center_no"),
      (assign, ":total_weight", 0),
      (try_for_range, ":cur_center_no", cities_begin, cities_end),
        (neq, ":center_no", ":cur_center_no"),
        (store_faction_of_party, ":center_faction_no", ":cur_center_no"),
        (eq, ":faction_no", ":center_faction_no"),
        
        (store_distance_to_party_from_party, ":cur_distance", ":center_no", ":cur_center_no"),
        (val_add, ":cur_distance", 1),
        
        (assign, ":new_weight", 100000),
        (val_div, ":new_weight", ":cur_distance"),
        (val_add, ":total_weight", ":new_weight"),
      (try_end),
      
      (assign, reg0, -1),
      
      (try_begin),
        (eq, ":total_weight", 0),
      (else_try),
        (store_random_in_range, ":random_weight", 0 , ":total_weight"),
        (assign, ":total_weight", 0),
        (assign, ":done", 0),
        (try_for_range, ":cur_center_no", cities_begin, cities_end),
          (eq, ":done", 0),
          (neq, ":center_no", ":cur_center_no"),
          (store_faction_of_party, ":center_faction_no", ":cur_center_no"),
          (eq, ":faction_no", ":center_faction_no"),
          
          (store_distance_to_party_from_party, ":cur_distance", ":center_no", ":cur_center_no"),
          (val_add, ":cur_distance", 1),
          
          (assign, ":new_weight", 100000),
          (val_div, ":new_weight", ":cur_distance"),
          (val_add, ":total_weight", ":new_weight"),
          (lt, ":random_weight", ":total_weight"),
          (assign, reg0, ":cur_center_no"),
          (assign, ":done", 1),
        (try_end),
      (try_end),
  ]),
  
  
  # script_get_relation_between_parties
  # Input: arg1 = party_no_1, arg2 = party_no_2
  # Output: reg0 = relation between parties
  ("get_relation_between_parties",
    [
      (store_script_param_1, ":party_no_1"),
      (store_script_param_2, ":party_no_2"),
      
      (store_faction_of_party, ":party_no_1_faction", ":party_no_1"),
      (store_faction_of_party, ":party_no_2_faction", ":party_no_2"),
      (try_begin),
        (eq, ":party_no_1_faction", ":party_no_2_faction"),
        (assign, reg0, 100),
      (else_try),
        (store_relation, ":relation", ":party_no_1_faction", ":party_no_2_faction"),
        (assign, reg0, ":relation"),
      (try_end),
  ]),
  # script_calculate_weekly_party_wage
  # Input: arg1 = party_no
  # Output: reg0 = weekly wage
  ("calculate_weekly_party_wage",
    [
      (store_script_param_1, ":party_no"),
      
      (assign, ":result", 0),
      (party_get_num_companion_stacks, ":num_stacks",":party_no"),
      (try_for_range, ":i_stack", 0, ":num_stacks"),
        (party_stack_get_troop_id, ":stack_troop",":party_no",":i_stack"),
        (party_stack_get_size, ":stack_size",":party_no",":i_stack"),
        (call_script, "script_npc_get_troop_wage", ":stack_troop", ":party_no"),
        (assign, ":cur_wage", reg0),
        (val_mul, ":cur_wage", ":stack_size"),
        (val_add, ":result", ":cur_wage"),
      (try_end),
      (assign, reg0, ":result"),
  ]),
  
  # script_calculate_player_faction_wage
  # Input: arg1 = party_no
  # Output: reg0 = weekly wage
  ("calculate_player_faction_wage",
    [
		(assign, ":non_garrison_wages", 0),
		(assign,':garrison_wages',0),
		(party_get_num_companion_stacks,':num_stacks','p_main_party'),
		(try_for_range,':stack_no',0,':num_stacks'),
			(party_stack_get_troop_id,':stack_troop','p_main_party',':stack_no'),
			(party_stack_get_size,':stack_size','p_main_party',':stack_no'),
			(call_script,'script_game_get_troop_wage',':stack_troop','p_main_party'),
			(assign,':cur_wage',reg0),
			(val_mul,':cur_wage',':stack_size'),
			(val_add,':non_garrison_wages',':cur_wage'),
		(try_end),
		(try_for_parties,':party'),
			(neq,':party','p_main_party'),
			(party_get_faction,':faction',':party'),
			(eq,':faction','fac_player_faction'),
			(party_get_num_companion_stacks,':num_stacks',':party'),
			(try_for_range,':stack_no',0,':num_stacks'),
				(party_stack_get_troop_id,':stack_troop',':party',':stack_no'),
				(party_stack_get_size,':stack_size',':party',':stack_no'),
				(call_script,'script_game_get_troop_wage',':stack_troop',':party'),
				(assign,':cur_wage',reg0),
				(val_mul,':cur_wage',':stack_size'),
				(val_add,':garrison_wages',':cur_wage'),
			(try_end),
		(try_end),
		(val_div,':garrison_wages',2), # half pay for being garrison
		(store_add, reg0, ":non_garrison_wages",':garrison_wages'),
  ]),
  
  
  # script_calculate_hero_weekly_net_income_and_add_to_wealth
  # Input: arg1 = troop_no
  # Output: none
  ("calculate_hero_weekly_net_income_and_add_to_wealth",
    [
      (store_script_param_1, ":troop_no"),
      
      (troop_get_slot, ":party_no", ":troop_no", slot_troop_leaded_party),
      (troop_get_slot, ":cur_wealth", ":troop_no", slot_troop_wealth),
      
      (assign, ":weekly_income", 500), #let every hero receive 500 denars by default
      
      (store_character_level, ":troop_level", ":troop_no"),
      (store_mul, ":level_income", ":troop_level", 10),
      (val_add, ":weekly_income", ":level_income"),
      
      (store_troop_faction,":faction_no", ":troop_no"),
      (try_begin), #check if troop is kingdom leader
        (faction_slot_eq, ":faction_no", slot_faction_leader, ":troop_no"),
        (val_add, ":weekly_income", 2000),
      (try_end),
      
      (assign, ":cur_weekly_wage", 0),
      (try_begin),
        (gt, ":party_no",0),
        (call_script, "script_calculate_weekly_party_wage", ":party_no"),
        (assign, ":cur_weekly_wage", reg0),
      (try_end),
      (val_sub, ":weekly_income", ":cur_weekly_wage"),
      
      (val_add, ":cur_wealth", ":weekly_income"),
      (troop_set_slot, ":troop_no", slot_troop_wealth, ":cur_wealth"),
  ]),
  
  # script_cf_reinforce_party
  # Input: arg1 = party_no,
  # Output: none
  # Adds reinforcement to party according to its type and faction
  ("cf_reinforce_party",
    [
      (store_script_param_1, ":party_no"),
      
      (store_faction_of_party, ":party_faction", ":party_no"),
      (party_get_slot, ":party_type",":party_no", slot_party_type),
      
      (faction_get_slot, ":party_template_a", ":party_faction", slot_faction_reinforcements_a),
      (faction_get_slot, ":party_template_b", ":party_faction", slot_faction_reinforcements_b),
      (faction_get_slot, ":party_template_c", ":party_faction", slot_faction_reinforcements_c),
      
      (assign, ":party_template", 0),
      (store_random_in_range, ":rand", 0, 100),
      (try_begin),
        (this_or_next|eq, ":party_type", spt_town),
        (eq, ":party_type", spt_castle),  #CASTLE OR TOWN
        (try_begin),
          (lt, ":rand", 50),
          (assign, ":party_template", ":party_template_a"),
        (else_try),
          (assign, ":party_template", ":party_template_b"),
        (try_end),
      (else_try),
        (eq, ":party_type", spt_kingdom_hero_party),
        (try_begin),
          (lt, ":rand", 33),
          (assign, ":party_template", ":party_template_a"),
        (else_try),
          (lt, ":rand", 66),
          (assign, ":party_template", ":party_template_b"),
        (else_try),
          (assign, ":party_template", ":party_template_c"),
        (try_end),
      (else_try),
      (try_end),
      
      (try_begin),
        (gt, ":party_template", 0),
        (party_add_template, ":party_no", ":party_template"),
      (try_end),
  ]),
  
  
  
  
  # script_get_troop_attached_party
  # Input: arg1 = troop_no
  # Output: reg0 = party_no (-1 if troop's party is not attached to a party)
  ("get_troop_attached_party",
    [
      (store_script_param_1, ":troop_no"),
      
      (troop_get_slot, ":party_no", ":troop_no", slot_troop_leaded_party),
      (assign, ":attached_party_no", -1),
      (try_begin),
        (ge, ":party_no", 0),
        (party_get_attached_to, ":attached_party_no", ":party_no"),
      (try_end),
      (assign, reg0, ":attached_party_no"),
  ]),
  
  
  # script_center_get_food_consumption
  # Input: arg1 = center_no
  # Output: reg0: food consumption (1 food item counts as 100 units)
  ("center_get_food_consumption",
    [
      (store_script_param_1, ":center_no"),
      (assign, ":food_consumption", 0),
      (try_begin),
        (party_slot_eq, ":center_no", slot_party_type, spt_town),
        (assign, ":food_consumption", 500),
      (else_try),
        (party_slot_eq, ":center_no", slot_party_type, spt_castle), #TODO: check garrison size?
        (assign, ":food_consumption", 50),
      (try_end),
      (assign, reg0, ":food_consumption"),
  ]),
  
  # script_center_get_food_store_limit
  # Input: arg1 = center_no
  # Output: reg0: food consumption (1 food item counts as 100 units)
  ("center_get_food_store_limit",
    [
      (store_script_param_1, ":center_no"),
      (assign, ":food_store_limit", 0),
      (try_begin),
        (party_slot_eq, ":center_no", slot_party_type, spt_town),
        (assign, ":food_store_limit", 30000),
      (else_try),
        (party_slot_eq, ":center_no", slot_party_type, spt_castle), #TODO: check garrison size?
        (assign, ":food_store_limit", 1500),
      (try_end),
      (assign, reg0, ":food_store_limit"),
  ]),
  
  # script_refresh_village_merchant_inventory
  # Input: arg1 = village_no
  # Output: none
  ("refresh_village_merchant_inventory",
    [
      (store_script_param_1, ":village_no"),
      (party_get_slot, ":merchant_troop", ":village_no", slot_town_merchant),
      (reset_item_probabilities,0),
      (set_item_probability_in_merchandise,"itm_salt",100),
      (set_item_probability_in_merchandise,"itm_rice",100),
      (troop_add_merchandise,":merchant_troop",itp_type_goods,3),
      (troop_ensure_inventory_space,":merchant_troop", 80),
  ]),
  
  # script_village_set_state
  # Input: arg1 = center_no arg2:new_state
  # Output: reg0: food consumption (1 food item counts as 100 units)
  ("village_set_state",
    [
      (store_script_param_1, ":village_no"),
      (store_script_param_2, ":new_state"),
      #      (party_get_slot, ":old_state", ":village_no", slot_town_state),
      (try_begin),
        (eq, ":new_state", 0),
        (eq, ":new_state", 0),
        (party_set_extra_text, ":village_no", "str_empty_string"),
        (party_set_slot, ":village_no", slot_town_raided_by, -1),
      (else_try),
        (eq, ":new_state", sts_being_raided),
        (party_set_extra_text, ":village_no", "@(Being Raided)"),
      (else_try),
        (eq, ":new_state", sts_looted),
        (party_set_extra_text, ":village_no", "@(Looted)"),
        (party_set_slot, ":village_no", slot_town_raided_by, -1),
      (else_try),
        (eq, ":new_state", sts_under_siege),
        (party_set_extra_text, ":village_no", "@(Under Siege)"),
      (try_end),
      (party_set_slot, ":village_no", slot_town_state, ":new_state"),
  ]),
  
  
  
  
  # script_process_alarms
  # Input: none
  # Output: none
  #called from triggers
  ("process_alarms",
    [
      (try_for_range, ":center_no", cities_begin, cities_end),
        (party_set_slot, ":center_no", slot_center_last_spotted_enemy, -1),
      (try_end),
      (assign, ":spotting_range", 6),
      (try_begin),
        (is_currently_night),
        (assign, ":spotting_range", 3),
      (try_end),
      (try_for_parties, ":party_no"),
        (party_slot_eq, ":party_no", slot_party_type, spt_kingdom_hero_party),
        (neg|party_is_in_any_town, ":party_no"),
        (store_faction_of_party, ":party_faction", ":party_no"),
        (try_for_range, ":center_no", cities_begin, cities_end),
          (store_distance_to_party_from_party, ":distance", ":party_no", ":center_no"),
          (lt, ":distance", ":spotting_range"),
          (store_faction_of_party, ":center_faction", ":center_no"),
          (store_relation, ":reln", ":center_faction", ":party_faction"),
          (lt, ":reln", 0),
          (party_set_slot, ":center_no", slot_center_last_spotted_enemy, ":party_no"),
        (try_end),
      (try_end),
      (try_for_range, ":center_no", cities_begin, cities_end),
        (store_faction_of_party, ":center_faction", ":center_no"),
        (eq, ":center_faction", "$players_kingdom"),
        (party_get_slot, ":enemy_party", ":center_no", slot_center_last_spotted_enemy),
        (ge, ":enemy_party", 0),
        (str_store_party_name, s1, ":center_no"),
        (display_message, "@Enemies spotted near {s1}"),
      (try_end),
  ]),
  
  
  # script_party_set_ai_state
  # Input: arg1 = party_no, arg2 = new_ai_state, arg3 = action_object (if necessary)
  # Output: none (Can fail)
  ("party_set_ai_state",
    [
      (store_script_param, ":party_no", 1),
      (store_script_param, ":new_ai_state", 2),
      (store_script_param, ":new_ai_object", 3),
      
      (party_get_slot, ":old_ai_state", ":party_no", slot_party_ai_state),
      (party_get_slot, ":old_ai_object", ":party_no", slot_party_ai_object),
      (party_get_attached_to, ":attached_to_party", ":party_no"),
      (assign, ":party_is_in_town", 0),
      (try_begin),
        (is_between, ":attached_to_party", cities_begin, cities_end),
        (assign, ":party_is_in_town", ":attached_to_party"),
      (try_end),
      
      (try_begin),
        (eq, ":old_ai_state", ":new_ai_state"),
        (eq, ":old_ai_object", ":new_ai_object"),
        #do nothing. Nothing is changed.
      (else_try),
        (try_begin),
          (eq, ":new_ai_state", spai_accompanying_army),
          (party_set_ai_behavior, ":party_no", ai_bhvr_escort_party),
          (party_set_ai_object, ":party_no", ":new_ai_object"),
          (party_set_flags, ":party_no", pf_default_behavior, 0),
          (try_begin),
            (gt, ":party_is_in_town", 0),
            (party_detach, ":party_no"),
          (try_end),
        (else_try),
          (eq, ":new_ai_state", spai_besieging_center),
          (party_get_position, pos1, ":new_ai_object"),
          (map_get_random_position_around_position, pos2, pos1, 2),
          (party_set_ai_behavior, ":party_no", ai_bhvr_travel_to_point),
          (party_set_ai_target_position, ":party_no", pos2),
          (party_set_ai_object, ":party_no", ":new_ai_object"),
          (party_set_flags, ":party_no", pf_default_behavior, 0),
          (try_begin),
            (gt, ":party_is_in_town", 0),
            (neq, ":party_is_in_town", ":new_ai_object"),
            (party_detach, ":party_no"),
          (try_end),
        (else_try),
          (eq, ":new_ai_state", spai_holding_center),
          (party_set_ai_behavior, ":party_no", ai_bhvr_travel_to_party),
          (party_set_ai_object, ":party_no", ":new_ai_object"),
          (party_set_flags, ":party_no", pf_default_behavior, 0),
          (try_begin),
            (gt, ":party_is_in_town", 0),
            (neq, ":party_is_in_town", ":new_ai_object"),
            (party_detach, ":party_no"),
          (try_end),
        (else_try),
          (eq, ":new_ai_state", spai_raiding_around_center),
          (party_get_position, pos1, ":new_ai_object"),
          (map_get_random_position_around_position, pos2, pos1, 1),
          (party_set_ai_behavior, ":party_no", ai_bhvr_patrol_location),
          (party_set_ai_patrol_radius, ":party_no", 10),
          (party_set_ai_target_position, ":party_no", pos2),
          (party_set_ai_object, ":party_no", ":new_ai_object"),
          (party_set_flags, ":party_no", pf_default_behavior, 0),
          (try_begin),
            (gt, ":party_is_in_town", 0),
            (neq, ":party_is_in_town", ":new_ai_object"),
            (party_detach, ":party_no"),
          (try_end),
        (else_try),
          (eq, ":new_ai_state", spai_raiding_village),
          (party_get_position, pos1, ":new_ai_object"),
          (map_get_random_position_around_position, pos2, pos1, 1),
          (party_set_ai_behavior, ":party_no", ai_bhvr_travel_to_point),
          (party_set_ai_target_position, ":party_no", pos2),
          (party_set_ai_object, ":party_no", ":new_ai_object"),
          (party_set_flags, ":party_no", pf_default_behavior, 0),
          (try_begin),
            (gt, ":party_is_in_town", 0),
            (neq, ":party_is_in_town", ":new_ai_object"),
            (party_detach, ":party_no"),
          (try_end),
        (else_try),
          (eq, ":new_ai_state", spai_engaging_army),
          (party_set_ai_behavior, ":party_no", ai_bhvr_attack_party),
          (party_set_ai_object, ":party_no", ":new_ai_object"),
          (party_set_flags, ":party_no", pf_default_behavior, 0),
          (try_begin),
            (gt, ":party_is_in_town", 0),
            (party_detach, ":party_no"),
          (try_end),
        (else_try),
          (eq, ":new_ai_state", spai_undefined),
          (party_set_ai_behavior, ":party_no", ai_bhvr_hold),
          (party_set_flags, ":party_no", pf_default_behavior, 0),
        (try_end),
      (try_end),
      
      (party_set_slot, ":party_no", slot_party_ai_state, ":new_ai_state"),
      (party_set_slot, ":party_no", slot_party_ai_object, ":new_ai_object"),
      
  ]),
  
  
  
  
  # script_kingdom_hero_decide_next_ai_state
  # Input: arg1 = troop_no
  # Output: none
  #called from triggers
  
  
  
  
  # script_process_kingdom_parties_ai
  # This is called more frequently than decide_kingdom_parties_ai
  # Input: none
  # Output: none
  #called from triggers
  ("process_kingdom_parties_ai",
    [
      #(try_for_range, ":troop_no", kingdom_heroes_begin, kingdom_heroes_end),
      #  (troop_slot_eq, ":troop_no", slot_troop_occupation, slto_kingdom_hero),
      #  (troop_slot_eq, ":troop_no", slot_troop_is_prisoner, 0),
      #  (troop_get_slot, ":party_no", ":troop_no", slot_troop_leaded_party),
      #  (gt, ":party_no", 0),
      #  (call_script, "script_process_hero_ai", ":troop_no"),
      #(try_end),
      (display_message,'@this is script ProcessKingdomPartiesAI'),
  ]),
  
  
  
  # script_process_hero_ai
  # This is called more frequently than decide_kingdom_parties_ai
  # Input: none
  # Output: none
  #called from triggers
  ("process_hero_ai",
    [
      
  ]),
  
  
  # script_change_troop_renown
  # Input: arg1 = troop_no, arg2 = relation difference
  # Output: none
  ("change_troop_renown",
    [
      (store_script_param_1, ":troop_no"),
      (store_script_param_2, ":renown_change"),
      
      (troop_get_slot, ":old_renown", ":troop_no", slot_troop_renown),
      (store_add, ":new_renown", ":old_renown", ":renown_change"),
      (val_max, ":new_renown", 0),
      (troop_set_slot, ":troop_no", slot_troop_renown, ":new_renown"),
      
      (try_begin),
        (eq, ":troop_no", "trp_player"),
        (str_store_troop_name, s1, ":troop_no"),
        (assign, reg12, ":renown_change"),
        (val_abs, reg12),
        (try_begin),
          (gt, ":renown_change", 0),
          (display_message, "@You gained {reg12} renown."),
        (else_try),
          (lt, ":renown_change", 0),
          (display_message, "@You loose {reg12} renown."),
        (try_end),
      (try_end),
      (call_script, "script_update_troop_notes", ":troop_no"),
  ]),
  
  
  # script_change_player_relation_with_troop
  # Input: arg1 = troop_no, arg2 = relation difference
  # Output: none
  ("change_player_relation_with_troop",
    [
      (store_script_param_1, ":troop_no"),
      (store_script_param_2, ":difference"),
      
      (troop_get_slot, ":player_relation", ":troop_no", slot_troop_player_relation),
      (troop_get_slot, ":player_favor", ":troop_no", slot_troop_player_favor),
      (assign, reg1, ":player_relation"),
      (val_add, ":player_relation", ":difference"),
      (val_clamp, ":player_relation", -100, 100),
      (assign, reg2, ":player_relation"),
      (val_add, ":player_favor", ":difference"),
      (val_add, ":player_favor", ":difference"),
      (troop_set_slot, ":troop_no", slot_troop_player_relation, ":player_relation"),
      (troop_set_slot, ":troop_no", slot_troop_player_favor, ":player_favor"),
      
      (str_store_troop_name, s1, ":troop_no"),
      (try_begin),
        (gt, ":difference", 0),
        (display_message, "str_troop_relation_increased"),
      (else_try),
        (lt, ":difference", 0),
        (display_message, "str_troop_relation_detoriated"),
      (try_end),
      
      (try_begin),
        (eq, ":troop_no", "$g_talk_troop"),
        (assign, "$g_talk_troop_relation", ":player_relation"),
        (call_script, "script_setup_talk_info"),
      (try_end),
  ]),
  
  
  
  # script_change_player_favor_of_troop
  # Input: arg1 = troop_no, arg2 = favor difference
  # Output: none
  ("change_player_favor_of_troop",
    [
      (store_script_param_1, ":troop_no"),
      (store_script_param_2, ":difference"),
      
      (troop_get_slot, ":player_favor", ":troop_no", slot_troop_player_favor),
      (val_add, ":player_favor", ":difference"),
      (troop_set_slot, ":troop_no", slot_troop_player_favor, ":player_favor"),
  ]),
  
  # script_change_player_relation_with_faction_ex
  # changes relations with other factions also (according to their relations between each other)
  # Input: arg1 = faction_no, arg2 = relation difference
  # Output: none
  ("change_player_relation_with_faction_ex",
    [
      (store_script_param_1, ":faction_no"),
      (store_script_param_2, ":difference"),
      
      (store_relation, ":player_relation", ":faction_no", "fac_player_faction"),
      (assign, reg1, ":player_relation"),
      (val_add, ":player_relation", ":difference"),
      (assign, reg2, ":player_relation"),
      (set_relation, ":faction_no", "fac_player_faction", ":player_relation"),
      
      (str_store_faction_name, s1, ":faction_no"),
      (try_begin),
        (gt, ":difference", 0),
        (display_message, "str_faction_relation_increased"),
      (else_try),
        (lt, ":difference", 0),
        (display_message, "str_faction_relation_detoriated"),
      (try_end),
      
      (try_for_range, ":other_faction", factions_begin, factions_end),
        (neq, ":faction_no", ":other_faction"),
        (store_relation, ":other_faction_relation", ":faction_no", ":other_faction"),
        (store_relation, ":player_relation", ":other_faction", "fac_player_faction"),
        (store_mul, ":relation_change", ":difference", ":other_faction_relation"),
        (val_div, ":relation_change", 100),
        (val_add, ":player_relation", ":relation_change"),
        (set_relation, ":other_faction", "fac_player_faction", ":player_relation"),
      (try_end),
  ]),
  
  # script_make_kingdom_hostile_to_player
  # Input: arg1 = faction_no, arg2 = relation difference
  # Output: none
  ("make_kingdom_hostile_to_player",
    [
      (store_script_param_1, ":input_faction"),
      (store_script_param_2, ":difference"),
      
      (try_begin),
        (lt, ":difference", 0),
        (faction_get_slot, ":top_kingdom", ":input_faction", slot_faction_vassal_of),
        (try_begin),
          (le, ":top_kingdom", 0),
          (assign, ":top_kingdom", ":input_faction"),
        (try_end),
        
        (try_for_range, ":kingdom_no", factions_begin, factions_end),
          (faction_get_slot, ":liege", ":kingdom_no", slot_faction_vassal_of),
          (this_or_next|eq, ":liege", ":top_kingdom"),
          (eq, ":kingdom_no", ":top_kingdom"),
          
          (store_relation, ":player_relation", ":kingdom_no", "fac_player_faction"),
          (val_min, ":player_relation", 0),
          (val_add, ":player_relation", ":difference"),
          (set_relation, ":kingdom_no", "fac_player_faction", ":player_relation"),
        (try_end),
      (try_end),
  ]),
  
  # script_change_player_honor
  # Input: arg1 = honor difference
  # Output: none
  ("change_player_honor",
    [
      (store_script_param_1, ":honor_dif"),
      
      (val_mul, ":honor_dif", 1000),
      (assign, ":temp_honor", 0),
      (assign, ":num_nonlinear_steps", 10),
      (try_begin),
        (gt, "$player_honor", 0),
        (lt, ":honor_dif", 0),
        (assign, ":num_nonlinear_steps", 0),
      (else_try),
        (lt, "$player_honor", 0),
        (gt, ":honor_dif", 0),
        (assign, ":num_nonlinear_steps", 3),
      (try_end),
      
      (try_begin),
        (ge, "$player_honor", 0),
        (assign, ":temp_honor", "$player_honor"),
        (try_begin),
          (val_sub, ":temp_honor", "$player_honor"),
        (try_end),
        (try_for_range, ":unused",0,":num_nonlinear_steps"),
          (ge, ":temp_honor", 10000),
          (val_div, ":temp_honor", 2),
          (val_div, ":honor_dif", 2),
        (try_end),
        (val_add, "$player_honor", ":honor_dif"),
    ]),
    
    # script_change_player_party_morale
    # Input: arg1 = morale difference
    # Output: none
    ("change_player_party_morale",
      [
        (store_script_param_1, ":morale_dif"),
        (assign, ":old_morale", "$g_party_morale_change_due_to_battles"),
        (store_add, ":new_morale", ":old_morale", ":morale_dif"),
        (val_clamp, ":new_morale", -100, 100),
        (assign, "$g_party_morale_change_due_to_battles", ":new_morale"),
        (try_begin),
          (lt, ":new_morale", ":old_morale"),
          (store_sub, reg1, ":old_morale", ":new_morale"),
          (display_message, "str_party_lost_morale"),
        (else_try),
          (gt, ":new_morale", ":old_morale"),
          (store_sub, reg1, ":new_morale", ":old_morale"),
          (display_message, "str_party_gained_morale"),
        (try_end),
        (call_script, "script_process_player_party_morale"),
    ]),
    
    # script_process_player_party_morale
    # called every day
    ("process_player_party_morale",
      [
        (party_get_num_companion_stacks, ":num_stacks","p_main_party"),
        (assign, ":num_men", 0),
        (try_for_range, ":i_stack", 0, ":num_stacks"),
          (party_stack_get_troop_id, ":stack_troop","p_main_party",":i_stack"),
          (try_begin),
            (troop_is_hero, ":stack_troop"),
            (val_add, ":num_men", 3),
          (else_try),
            (party_stack_get_size, ":stack_size","p_main_party",":i_stack"),
            (val_add, ":num_men", ":stack_size"),
          (try_end),
        (try_end),
        (assign, "$g_player_party_morale_modifier_party_size", ":num_men"),
        
        (store_skill_level, ":player_leadership", "skl_leadership", "trp_player"),
        (store_mul, "$g_player_party_morale_modifier_leadership", ":player_leadership", 5),
        (assign, ":new_morale", "$g_player_party_morale_modifier_leadership"),
        (val_sub, ":new_morale", "$g_player_party_morale_modifier_party_size"),
        (val_add, ":new_morale", 50),
        
        (assign, ":available_food", 0),
        (assign, "$g_player_party_morale_modifier_food", 0),
        (try_for_range, ":cur_edible", morale_boosters_begin, morale_boosters_end),
          (player_has_item, ":cur_edible"),
          (try_begin),
            (is_between, ":cur_edible", food_begin, food_end),
            (val_add, ":available_food", 1),
          (try_end),
          (item_get_slot, ":food_bonus", ":cur_edible", slot_item_food_bonus),
          (val_add, "$g_player_party_morale_modifier_food", ":food_bonus"),
        (try_end),
        (val_add, ":new_morale", "$g_player_party_morale_modifier_food"),
        
        (try_begin),
          (eq, ":available_food", 0),
          (assign, "$g_player_party_morale_modifier_no_food", 30),
          (val_sub, ":new_morale", "$g_player_party_morale_modifier_no_food"),
        (else_try),
          (assign, "$g_player_party_morale_modifier_no_food", 0),
        (try_end),
        
        (assign, "$g_player_party_morale_modifier_debt", 0),
        (try_begin),
          (gt, "$g_player_debt_to_party_members", 0),
          (call_script, "script_calculate_player_faction_wage"),
          (assign, ":total_wages", reg0),
          (store_mul, "$g_player_party_morale_modifier_debt", "$g_player_debt_to_party_members", 10),
          (val_div, "$g_player_party_morale_modifier_debt", ":total_wages"),
          (val_clamp, "$g_player_party_morale_modifier_debt", 1, 31),
          (val_sub, ":new_morale", "$g_player_party_morale_modifier_debt"),
        (try_end),
        
        (val_add, ":new_morale", "$g_party_morale_change_due_to_battles"),
        
        (val_clamp, ":new_morale", 0, 100),
        (party_set_morale, "p_main_party", ":new_morale"),
    ]),
    
    
    ("diplomacy_start_war_between_kingdoms", #sets relations between two kingdoms and their vassals.
      [
        (store_script_param_1, ":kingdom_a"),
        (store_script_param_2, ":kingdom_b"),
        
        (store_relation, ":relation", ":kingdom_a", ":kingdom_b"),
        (val_min, ":relation", -10),
        (val_add, ":relation", -30),
        (set_relation, ":kingdom_a", ":kingdom_b", ":relation"),
        
        (try_for_range, ":kingdom_vassal", factions_begin, factions_end),
          (faction_get_slot, ":liege", ":kingdom_vassal", slot_faction_vassal_of),
          (eq, ":liege", ":kingdom_a"),
          (store_relation, ":relation", ":kingdom_vassal", ":kingdom_b"),
          (val_min, ":relation", 0),
          (val_add, ":relation", -20),
          (set_relation, ":kingdom_vassal", ":kingdom_b", ":relation"),
          
          (try_for_range, ":kingdom_b_vassal", factions_begin, factions_end),
            (faction_get_slot, ":liege2", ":kingdom_b_vassal", slot_faction_vassal_of),
            (eq, ":liege2", ":kingdom_b"),
            (store_relation, ":relation", ":kingdom_vassal", ":kingdom_b_vassal"),
            (val_min, ":relation", 0),
            (val_add, ":relation", -15),
            (set_relation, ":kingdom_vassal", ":kingdom_b_vassal", ":relation"),
          (try_end),
        (else_try),
          (eq, ":liege", ":kingdom_b"),
          (store_relation, ":relation", ":kingdom_vassal", ":kingdom_a"),
          (val_min, ":relation", 0),
          (val_add, ":relation", -20),
          (set_relation, ":kingdom_vassal", ":kingdom_a", ":relation"),
        (try_end),
        
        (try_begin),
          (eq, "$players_kingdom", ":kingdom_a"),
          (call_script, "script_diplomacy_start_war_between_kingdoms", ":kingdom_b", "fac_player_faction"),
        (else_try),
          (eq, "$players_kingdom", ":kingdom_b"),
          (call_script, "script_diplomacy_start_war_between_kingdoms", ":kingdom_a", "fac_player_faction"),
        (try_end),
    ]),
    
    ("diplomacy_start_peace_between_kingdoms", #sets relations between two kingdoms and their vassals.
      [
        (store_script_param_1, ":kingdom_a"),
        (store_script_param_2, ":kingdom_b"),
        
        (store_relation, ":relation", ":kingdom_a", ":kingdom_b"),
        (val_max, ":relation", 0),
        (set_relation, ":kingdom_a", ":kingdom_b", ":relation"),
        (call_script, "script_exchange_prisoners_between_factions", ":kingdom_a", ":kingdom_b"),
        
        (try_for_range, ":kingdom_vassal", factions_begin, factions_end),
          (faction_get_slot, ":liege", ":kingdom_vassal", slot_faction_vassal_of),
          (eq, ":liege", ":kingdom_a"),
          (store_relation, ":relation", ":kingdom_vassal", ":kingdom_b"),
          (val_max, ":relation", 0),
          (set_relation, ":kingdom_vassal", ":kingdom_b", ":relation"),
          (call_script, "script_exchange_prisoners_between_factions", ":kingdom_vassal", ":kingdom_b"),
          
          (try_for_range, ":kingdom_b_vassal", factions_begin, factions_end),
            (faction_get_slot, ":liege2", ":kingdom_b_vassal", slot_faction_vassal_of),
            (eq, ":liege2", ":kingdom_b"),
            (store_relation, ":relation", ":kingdom_vassal", ":kingdom_b_vassal"),
            (val_max, ":relation", 0),
            (set_relation, ":kingdom_vassal", ":kingdom_b_vassal", ":relation"),
            (call_script, "script_exchange_prisoners_between_factions", ":kingdom_vassal", ":kingdom_b_vassal"),
          (try_end),
        (else_try),
          (eq, ":liege", ":kingdom_b"),
          (store_relation, ":relation", ":kingdom_vassal", ":kingdom_a"),
          (val_max, ":relation", 0),
          (set_relation, ":kingdom_vassal", ":kingdom_a", ":relation"),
          (call_script, "script_exchange_prisoners_between_factions", ":kingdom_vassal", ":kingdom_a"),
        (try_end),
        
        (try_begin),
          (eq, "$players_kingdom", ":kingdom_a"),
          (call_script, "script_diplomacy_start_peace_between_kingdoms", ":kingdom_b", "fac_player_faction"),
        (else_try),
          (eq, "$players_kingdom", ":kingdom_b"),
          (call_script, "script_diplomacy_start_peace_between_kingdoms", ":kingdom_a", "fac_player_faction"),
        (try_end),
    ]),
    
    ##  ("diplomacy_make_kingdom_independent",
    ##    [
    ##      (store_script_param_1, ":kingdom"),
    ##      (faction_set_slot, ":kingdom", slot_faction_vassal_of, -1),
    ##  ]),
    
    ("diplomacy_make_kingdom_vassal_of_kingdom",
      [
        (store_script_param_1, ":vassal_kingdom"),
        (store_script_param_2, ":protector_kingdom"),
        (store_relation, ":cur_relation", ":vassal_kingdom", ":protector_kingdom"),
        (val_max, ":cur_relation", 0),
        (set_relation, ":vassal_kingdom", ":protector_kingdom", ":cur_relation"),
        (call_script, "script_exchange_prisoners_between_factions", ":vassal_kingdom", ":protector_kingdom"),
        (try_for_range, ":cur_kingdom", factions_begin, factions_end),
          (faction_get_slot, ":cur_liege", ":cur_kingdom", slot_faction_vassal_of),
          (try_begin),
            (eq, ":cur_liege", ":protector_kingdom"),
            (store_relation, ":cur_relation", ":vassal_kingdom", ":cur_kingdom"),
            (val_max, ":cur_relation", 0),
            (set_relation, ":vassal_kingdom", ":cur_kingdom", ":cur_relation"),
            (call_script, "script_exchange_prisoners_between_factions", ":vassal_kingdom", ":cur_kingdom"),
          (else_try),
            (neq, ":cur_liege", ":vassal_kingdom"),
            (store_relation, ":cur_relation", ":protector_kingdom", ":cur_kingdom"),
            (set_relation, ":vassal_kingdom", ":cur_kingdom", ":cur_relation"),
            (ge, ":cur_relation", 0),
            (call_script, "script_exchange_prisoners_between_factions", ":vassal_kingdom", ":cur_kingdom"),
          (try_end),
        (try_end),
        (try_begin),
          (eq, "$players_kingdom", ":protector_kingdom"),
          (store_relation, ":cur_relation", ":vassal_kingdom", "fac_player_faction"),
          (val_max, ":cur_relation", 0),
          (set_relation, ":vassal_kingdom", "fac_player_faction", ":cur_relation"),
        (else_try),
          (neq, "$players_kingdom", ":vassal_kingdom"),
          (store_relation, ":cur_relation", ":protector_kingdom", "fac_player_faction"),
          (set_relation, ":vassal_kingdom", "fac_player_faction", ":cur_relation"),
        (try_end),
        
        (faction_set_slot, ":vassal_kingdom", slot_faction_vassal_of, ":protector_kingdom"),
        (try_for_range, ":cur_kingdom", factions_begin, factions_end),
          (faction_get_slot, ":cur_liege", ":cur_kingdom", slot_faction_vassal_of),
          (eq, ":cur_liege", ":vassal_kingdom"),
          (call_script, "script_diplomacy_make_kingdom_vassal_of_kingdom", ":cur_kingdom", ":protector_kingdom"),
        (try_end),
    ]),
    
    # script_exchange_prisoners_between_factions
    # Input: arg1 = faction_no_1, arg2 = faction_no_2
    ("exchange_prisoners_between_factions",
      [
        (store_script_param_1, ":faction_no_1"),
        (store_script_param_2, ":faction_no_2"),
        
        (try_for_parties, ":party_no"),
          (store_faction_of_party, ":party_faction", ":party_no"),
          (this_or_next|eq, ":party_faction", ":faction_no_1"),
          (eq, ":party_faction", ":faction_no_2"),
          (party_get_num_prisoner_stacks, ":num_stacks", ":party_no"),
          (try_for_range_backwards, ":troop_iterator", 0, ":num_stacks"),
            (party_prisoner_stack_get_troop_id, ":cur_troop_id", ":party_no", ":troop_iterator"),
            (store_troop_faction, ":cur_faction", ":cur_troop_id"),
            (this_or_next|eq, ":cur_faction", ":faction_no_1"),
            (eq, ":cur_faction", ":faction_no_2"),
            (try_begin),
              (troop_is_hero, ":cur_troop_id"),
              (troop_set_slot, ":cur_troop_id", slot_troop_is_prisoner, 0),
            (try_end),
            (party_prisoner_stack_get_size, ":stack_size",":party_no",":troop_iterator"),
            (party_remove_prisoners, ":party_no", ":troop_iterator", ":stack_size"),
          (try_end),
      ]),
      
      
      
      
      # script_get_information_about_troops_position
      # Input: arg1 = troop_no, arg2 = time (0 if present tense, 1 if past tense)
      # Output: s1 = String, reg0 = knows-or-not
      ("get_information_about_troops_position",
        [
          (store_script_param_1, ":troop_no"),
          (store_script_param_2, reg3),
          (troop_get_type, reg4, ":troop_no"),
          (str_store_troop_name_link, s2, ":troop_no"),
          
          (assign, ":found", 0),
          (troop_get_slot, ":center_no", ":troop_no", slot_troop_cur_center),
          (try_begin),
            (gt, ":center_no", 0),
            (is_between, ":center_no", cities_begin, cities_end),
            (str_store_party_name_link, s3, ":center_no"),
            (str_store_string, s1, "@{s2} {reg3?was:is currently} at {s3}."),
            (assign, ":found", 1),
          (else_try),
            (troop_get_slot, ":party_no", ":troop_no", slot_troop_leaded_party),
            (gt, ":party_no", 0),
            (call_script, "script_get_troop_attached_party", ":troop_no"),
            (assign, ":center_no", reg0),
            (try_begin),
              (is_between, ":center_no", cities_begin, cities_end),
              (str_store_party_name_link, s3, ":center_no"),
              (str_store_string, s1, "@{s2} {reg3?was:is currently} at {s3}."),
              (assign, ":found", 1),
            (else_try),
              (get_party_ai_behavior, ":ai_behavior", ":party_no"),
              (eq, ":ai_behavior", ai_bhvr_travel_to_party),
              (get_party_ai_object, ":ai_object", ":party_no"),
              (is_between, ":ai_object", cities_begin, cities_end),
              (call_script, "script_get_closest_center", ":party_no"),
              (str_store_party_name_link, s4, reg0),
              (str_store_party_name_link, s3, ":ai_object"),
              (str_store_string, s1, "@{s2} {reg3?was:is} travelling to {s3} and {reg4?she:he} {reg3?was:should be} close to {s4}{reg3?: at the moment}."),
              (assign, ":found", 1),
            (else_try),
              (call_script, "script_get_closest_center", ":party_no"),
              (str_store_party_name_link, s3, reg0),
              (str_store_string, s1, "@{s2} {reg3?was:is} in wilderness and {reg4?she:he} {reg3?was:should be} close to {s3}{reg3?: at the moment}."),
              (assign, ":found", 1),
            (try_end),
          (try_end),
          (try_begin),
            (eq, ":found", 0),
            (str_store_string, s1, "@{reg3?{s2}'s location was unknown:I don't know where {s2} is}."),
          (try_end),
          (assign, reg0, ":found"),
      ]),
      
      # script_recruit_troop_as_companion
      # Input: arg1 = troop_no,
      # Output: none
      ("recruit_troop_as_companion",
        [
          (store_script_param_1, ":troop_no"),
          (troop_set_slot, ":troop_no", slot_troop_occupation, slto_player_companion),
          (troop_set_auto_equip, ":troop_no",0),
          (party_add_members, "p_main_party", ":troop_no", 1),
          (str_store_troop_name, s6, ":troop_no"),
          (display_message, "@{s6} has joined your party"),
      ]),
      
      
      # script_setup_random_scene
      # Input: arg1 = center_no, arg2 = mission_template_no
      # Output: none
      ("setup_random_scene",
        [
          (party_get_current_terrain, ":terrain_type", "p_main_party"),
          (assign, ":scene_to_use", "scn_random_scene"),
          (try_begin),
            (eq, ":terrain_type", rt_steppe),
            (assign, ":scene_to_use", "scn_random_scene_steppe"),
          (else_try),
            (eq, ":terrain_type", rt_plain),
            (assign, ":scene_to_use", "scn_random_scene_plain"),
          (else_try),
            (eq, ":terrain_type", rt_snow),
            (assign, ":scene_to_use", "scn_random_scene_snow"),
          (else_try),
            (eq, ":terrain_type", rt_desert),
            (assign, ":scene_to_use", "scn_random_scene_desert"),
          (else_try),
            (eq, ":terrain_type", rt_steppe_forest),
            (assign, ":scene_to_use", "scn_random_scene_steppe_forest"),
          (else_try),
            (eq, ":terrain_type", rt_forest),
            (assign, ":scene_to_use", "scn_random_scene_plain_forest"),
          (else_try),
            (eq, ":terrain_type", rt_snow_forest),
            (assign, ":scene_to_use", "scn_random_scene_snow_forest"),
          (else_try),
            (eq, ":terrain_type", rt_desert_forest),
            (assign, ":scene_to_use", "scn_random_scene_desert_forest"),
          (try_end),
          (jump_to_scene,":scene_to_use"),
      ]),
      
      # script_enter_dungeon
      # Input: arg1 = center_no, arg2 = mission_template_no
      # Output: none
      
      
      # script_enter_court
      # Input: arg1 = center_no
      # Output: none
      
      
      # script_find_high_ground_around_pos1
      # Input: pos1 should hold center_position_no
      #        arg1: search_radius (in meters)
      # Output: pos52 contains highest ground within <search_radius> meters of team leader
      # Destroys position registers: pos10, pos11, pos15
      ("find_high_ground_around_pos1",
        [
          (store_script_param_1, ":search_radius"),
          (val_mul, ":search_radius", 100),
          (get_scene_boundaries, pos10,pos11),
          (team_get_leader, ":ai_leader", "$ai_team"),
          (agent_get_position, pos1, ":ai_leader"),
          (set_fixed_point_multiplier, 100),
          (position_get_x, ":o_x", pos1),
          (position_get_y, ":o_y", pos1),
          (store_sub, ":min_x", ":o_x", ":search_radius"),
          (store_sub, ":min_y", ":o_y", ":search_radius"),
          (store_add, ":max_x", ":o_x", ":search_radius"),
          (store_add, ":max_y", ":o_y", ":search_radius"),
          (position_get_x, ":scene_min_x", pos10),
          (position_get_x, ":scene_max_x", pos11),
          (position_get_y, ":scene_min_y", pos10),
          (position_get_y, ":scene_max_y", pos11),
          (val_max, ":min_x", ":scene_min_x"),
          (val_max, ":min_y", ":scene_min_y"),
          (val_min, ":max_x", ":scene_max_x"),
          (val_min, ":max_y", ":scene_max_y"),
          
          (store_div, ":min_x_meters", ":min_x", 100),
          (store_div, ":min_y_meters", ":min_y", 100),
          (store_div, ":max_x_meters", ":max_x", 100),
          (store_div, ":max_y_meters", ":max_y", 100),
          
          (assign, ":highest_pos_z", -10000),
          (copy_position, pos52, pos1),
          (init_position, pos15),
          
          (try_for_range, ":i_x", ":min_x_meters", ":max_x_meters"),
            (store_mul, ":i_x_cm", ":i_x", 100),
            (try_for_range, ":i_y", ":min_y_meters", ":max_y_meters"),
              (store_mul, ":i_y_cm", ":i_y", 100),
              (position_set_x, pos15, ":i_x_cm"),
              (position_set_y, pos15, ":i_y_cm"),
              (position_set_z, pos15, 10000),
              (position_set_z_to_ground_level, pos15),
              (position_get_z, ":cur_pos_z", pos15),
              (try_begin),
                (gt, ":cur_pos_z", ":highest_pos_z"),
                (copy_position, pos52, pos15),
                (assign, ":highest_pos_z", ":cur_pos_z"),
              (try_end),
            (try_end),
          (try_end),
      ]),
      
      # script_select_battle_tactic
      # Input: none
      # Output: none
      ("select_battle_tactic",
        [
          (assign, "$ai_battle_tactic", 0),
          (assign,":defense_not_an_option",0),
          (try_begin),
            (eq, "$cant_leave_encounter", 1),
            #        (encountered_party_is_attacker),
            (assign,":defense_not_an_option",1),
          (try_end),
          (get_player_agent_no, ":player_agent"),
          (agent_get_team, ":player_team", ":player_agent"),
          #Note that enemy is the player here.
          (assign,":enemy_team",":player_team"),
          (try_begin),
            (eq, ":player_team", 0),
            (assign, "$ai_team", 1),
          (else_try),
            (assign, "$ai_team", 0),
          (try_end),
          #      (store_sub,"$ai_team",":player_team", 1),
          (call_script, "script_team_get_class_percentages", "$ai_team"),
          #      (assign, ":ai_perc_infantry", reg0),
          (assign, ":ai_perc_archers",  reg1),
          #      (assign, ":ai_perc_cavalry",  reg2),
          (call_script, "script_team_get_class_percentages", ":enemy_team"),
          #      (assign, ":enemy_perc_infantry", reg0),
          #      (assign, ":enemy_perc_archers",  reg1),
          #      (assign, ":enemy_perc_cavalry",  reg2),
          
          (try_begin),
            (eq,":defense_not_an_option",0),
            (gt, ":ai_perc_archers",  25),
            (assign, "$ai_battle_tactic", btactic_hold),
          (else_try),
            (assign, "$ai_battle_tactic", btactic_follow_leader),
          (try_end),
      ]),
      
      # script_battle_tactic_init
      # Input: none
      # Output: none
      ("battle_tactic_init",
        [
          (team_get_leader, ":ai_leader", "$ai_team"),
          (try_begin),
            (eq, "$ai_battle_tactic", btactic_hold),
            (agent_get_position, pos1, ":ai_leader"),
            (call_script, "script_find_high_ground_around_pos1", 30),
            (copy_position, pos1, pos52),
            (call_script, "script_find_high_ground_around_pos1", 30), # call again just in case we are not at peak point.
            (copy_position, pos1, pos52),
            (call_script, "script_find_high_ground_around_pos1", 30), # call again just in case we are not at peak point.
            (team_give_order, "$ai_team", grc_everyone, mordr_hold),
            (team_set_order_position, "$ai_team", grc_everyone, pos52),
            #        (team_give_order, "$ai_team", grc_archers, mordr_advance),
          (else_try),
            (eq, "$ai_battle_tactic", btactic_follow_leader),
            (team_get_leader, ":ai_leader", "$ai_team"),
            (agent_set_speed_limit, ":ai_leader", 9),
            (team_give_order, "$ai_team", grc_everyone, mordr_charge),
            (team_give_order, "$ai_team", grc_everyone, mordr_follow),
          (try_end),
          
          (assign, "$everyone_charge_order_given", 0),
      ]),
      
      # script_battle_tactic_apply
      # Input: none
      # Output: none
      ("battle_tactic_apply",
        [
          (assign,":enemy_team",0),
          (store_mission_timer_a,":mission_time"),
          (try_begin),
            (eq, "$ai_battle_tactic", btactic_hold),
            (copy_position, pos1, pos52),
            (call_script, "script_get_closest3_distance_of_team_at_pos1", ":enemy_team"),
            (store_add, ":avg_dist", reg0,reg1),
            (val_add, ":avg_dist", reg2),
            (val_div, ":avg_dist", 3),
            (try_begin),
              (lt, ":avg_dist", 3500),
              (eq, "$everyone_charge_order_given", 0),
              (assign, "$everyone_charge_order_given", 1),
              (team_give_order, "$ai_team", grc_everyone, mordr_charge),
            (try_end),
          (else_try),
            (eq, "$ai_battle_tactic", btactic_follow_leader),
            (eq, "$everyone_charge_order_given", 0),
            (team_get_leader, ":ai_leader", "$ai_team"),
            (ge, ":ai_leader", 0),
            (agent_get_position, pos1, ":ai_leader"),
            (call_script, "script_get_closest3_distance_of_team_at_pos1", ":enemy_team"),
            (store_add, ":avg_dist", reg0,reg1),
            (val_add, ":avg_dist", reg2),
            (val_div, ":avg_dist", 3),
            (try_begin),
              (lt, ":avg_dist", 3500),
              (ge,":mission_time",20),
              (assign, "$everyone_charge_order_given", 1),
              (team_give_order, "$ai_team", grc_everyone, mordr_charge),
            (try_end),
          (try_end),
          
          (try_begin), # charge everyone after a while
            (eq, "$everyone_charge_order_given", 0),
            (ge,":mission_time",300),
            (assign, "$everyone_charge_order_given", 1),
            (team_give_order, "$ai_team", grc_everyone, mordr_charge),
          (try_end),
          
      ]),
      
      ##  # script_siege_defender_tactic_apply
      ##  # Input: none
      ##  # Output: none
      ##  ("siege_defender_tactic_apply",
      ##    [
      ##      (try_begin),
      ##        (eq, "$defender_team", 1),
      ##        (ge, "$belfry_positioned", 2),
      ##
      ##        (assign, ":enemy_too_weak", 0),
      ##        (try_begin),
      ##          (ge, "$attacker_reinforcement_stage", 2),
      ##          (call_script, "script_calculate_team_strength", "$defender_team"),
      ##          (assign, ":defender_strength", reg0),
      ##          (call_script, "script_calculate_team_strength", "$attacker_team"),
      ##          (assign, ":attacker_strength", reg0),
      ##          (store_mul, ":attacker_strength_multiplied", ":attacker_strength", 2),
      ##          (ge, ":defender_strength", ":attacker_strength_multiplied"),
      ##          (assign, ":enemy_too_weak", 1),
      ##        (try_end),
      ##
      ##        (try_begin),
      ##          (eq, ":enemy_too_weak", 1),
      ##          (neq, "$ai_battle_tactic", btactic_charge),
      ##          (assign, "$ai_battle_tactic", btactic_charge),
      ##          (team_give_order, "$defender_team", grc_infantry, mordr_charge),
      ##        (else_try),
      ##          (neq, "$ai_battle_tactic", btactic_charge),
      ##          (neq, "$ai_battle_tactic", btactic_hold),
      ##          (assign, "$ai_battle_tactic", btactic_hold),
      ##          (team_give_order, "$defender_team", grc_infantry, mordr_hold),
      ##          (team_give_order, "$defender_team", grc_heroes, mordr_hold),
      ##          (entry_point_get_position,pos1,10),
      ##          (team_set_order_position, "$defender_team", grc_infantry, pos1),
      ##          (team_set_order_position, "$defender_team", grc_heroes, pos1),
      ##        (try_end),
      ##      (try_end),
      ##  ]),
      
      
      # script_team_get_class_percentages
      # Input: arg1: team_no
      # Output: reg0: percentage infantry, reg1: percentage archers, reg2: percentage cavalry
      ("team_get_class_percentages",
        [
          (assign, ":num_infantry", 0),
          (assign, ":num_archers", 0),
          (assign, ":num_cavalry", 0),
          (assign, ":num_total", 0),
          (store_script_param_1, ":team_no"),
          (try_for_agents,":cur_agent"),
            (agent_is_alive, ":cur_agent"),
            (agent_is_human, ":cur_agent"),
            (agent_get_team, ":agent_team", ":cur_agent"),
            (eq, ":agent_team", ":team_no"),
            
            (val_add, ":num_total", 1),
            (agent_get_class, ":agent_class", ":cur_agent"),
            (try_begin),
              (eq, ":agent_class", grc_infantry),
              (val_add,  ":num_infantry", 1),
            (else_try),
              (eq, ":agent_class", grc_archers),
              (val_add,  ":num_archers", 1),
            (else_try),
              (eq, ":agent_class", grc_cavalry),
              (val_add,  ":num_cavalry", 1),
            (try_end),
          (try_end),
          (try_begin),
            (eq,  ":num_total", 0),
            (assign,  ":num_total", 1),
          (try_end),
          (store_mul, ":perc_infantry",":num_infantry",100),
          (val_div, ":perc_infantry",":num_total"),
          (store_mul, ":perc_archers",":num_archers",100),
          (val_div, ":perc_archers",":num_total"),
          (store_mul, ":perc_cavalry",":num_cavalry",100),
          (val_div, ":perc_cavalry",":num_total"),
          (assign, reg0, ":perc_infantry"),
          (assign, reg1, ":perc_archers"),
          (assign, reg2, ":perc_cavalry"),
      ]),
      
      # script_get_closest3_distance_of_team_at_pos1
      # Input: arg1: team_no, pos1
      # Output: reg0: distance in cms.
      ("get_closest3_distance_of_team_at_pos1",
        [
          (assign, ":min_distance_1", 100000),
          (assign, ":min_distance_2", 100000),
          (assign, ":min_distance_3", 100000),
          
          (store_script_param_1, ":team_no"),
          (try_for_agents,":cur_agent"),
            (agent_is_alive, ":cur_agent"),
            (agent_is_human, ":cur_agent"),
            (agent_get_team, ":agent_team", ":cur_agent"),
            (eq, ":agent_team", ":team_no"),
            
            (agent_get_position, pos2, ":cur_agent"),
            (get_distance_between_positions,":cur_dist",pos2,pos1),
            (try_begin),
              (lt, ":cur_dist", ":min_distance_1"),
              (assign, ":min_distance_3", ":min_distance_2"),
              (assign, ":min_distance_2", ":min_distance_1"),
              (assign, ":min_distance_1", ":cur_dist"),
            (else_try),
              (lt, ":cur_dist", ":min_distance_2"),
              (assign, ":min_distance_3", ":min_distance_2"),
              (assign, ":min_distance_2", ":cur_dist"),
            (else_try),
              (lt, ":cur_dist", ":min_distance_3"),
              (assign, ":min_distance_3", ":cur_dist"),
            (try_end),
          (try_end),
          
          (assign, ":total_distance", 0),
          (assign, ":total_count", 0),
          (try_begin),
            (lt, ":min_distance_1", 100000),
            (val_add, ":total_distance", ":min_distance_1"),
            (val_add, ":total_count", 1),
          (try_end),
          (try_begin),
            (lt, ":min_distance_2", 100000),
            (val_add, ":total_distance", ":min_distance_2"),
            (val_add, ":total_count", 1),
          (try_end),
          (try_begin),
            (lt, ":min_distance_3", 100000),
            (val_add, ":total_distance", ":min_distance_3"),
            (val_add, ":total_count", 1),
          (try_end),
          (assign, ":average_distance", 100000),
          (try_begin),
            (gt, ":total_count", 0),
            (store_div, ":average_distance", ":total_distance", ":total_count"),
          (try_end),
          (assign, reg0, ":average_distance"),
      ]),
      
            
      # script_check_friendly_kills
      # Input: none
      # Output: none (changes the morale of the player's party)
      ("check_friendly_kills",
        [(get_player_agent_own_troop_kill_count, ":count"),
          (try_begin),
            (neq, "$g_player_current_own_troop_kills", ":count"),
            (val_sub, ":count", "$g_player_current_own_troop_kills"),
            (val_add, "$g_player_current_own_troop_kills", ":count"),
            (val_mul, ":count", -1),
            (call_script, "script_change_player_party_morale", ":count"),
          (try_end),
      ]),
      
      # script_simulate_retreat
      # Input: arg1 = players_side_damage, arg2 = enemy_side_damage
      # Output: none
      ("simulate_retreat",
        [
          (set_show_messages, 0),
          (store_script_param_1, ":players_side_damage"),
          (store_script_param_2, ":enemy_side_damage"),
          
          (assign, ":players_side_strength", 0),
          (assign, ":enemy_side_strength", 0),
          
          (assign, ":do_calculate", 1),
          (try_begin),
            (eq, "$pin_player_fallen", 0),
            (try_for_agents, ":cur_agent"),
              (agent_is_human, ":cur_agent"),
              (agent_is_alive, ":cur_agent"),
              
              (agent_get_troop_id, ":cur_troop", ":cur_agent"),
              (store_character_level, ":cur_level", ":cur_troop"),
              (val_add, ":cur_level", 5),
              (try_begin),
                (troop_is_hero, ":cur_troop"),
                (val_add, ":cur_level", 5),
              (try_end),
              (try_begin),
                (agent_is_ally, ":cur_agent"),
                (val_add, ":players_side_strength", ":cur_level"),
              (else_try),
                (val_add, ":enemy_side_strength", ":cur_level"),
              (try_end),
            (try_end),
            (lt, ":enemy_side_strength", ":players_side_strength"),
            (assign, ":do_calculate", 0),
          (try_end),
          
          (try_begin),
            (eq, ":do_calculate", 1),
            
            (assign, "$g_last_mission_player_damage", 0),
            (party_clear, "p_temp_party"),
            (party_clear, "p_temp_party_2"),
            (call_script, "script_simulate_battle_with_agents_aux", 0, ":players_side_damage"),
            (call_script, "script_simulate_battle_with_agents_aux", 1, ":enemy_side_damage"),
            
            (assign, ":display_casualties", 0),
            
            (try_begin),
              (gt, "$g_last_mission_player_damage", 0),
              (assign, ":display_casualties", 1),
              (assign, reg1, "$g_last_mission_player_damage"),
              (str_store_string, s12, "str_casualty_display_hp"),
            (else_try),
              (str_clear, s12),
            (try_end),
            
            (call_script, "script_print_casualties_to_s0", "p_temp_party", 1),
            (try_begin),
              (party_get_num_companion_stacks, ":num_stacks", "p_temp_party"),
              (gt, ":num_stacks", 0),
              (assign, ":display_casualties", 1),
            (try_end),
            (str_store_string_reg, s10, s0),
            
            (call_script, "script_print_casualties_to_s0", "p_temp_party_2", 1),
            (try_begin),
              (party_get_num_companion_stacks, ":num_stacks", "p_temp_party_2"),
              (gt, ":num_stacks", 0),
              (assign, ":display_casualties", 1),
            (try_end),
            (str_store_string_reg, s11, s0),
            (try_begin),
              (eq, ":display_casualties", 1),
              (dialog_box,"str_casualty_display", "str_retreat"),
            (try_end),
          (try_end),
          (set_show_messages, 1),
          
          #Calculating morale penalty (can be between 0-30)
          (assign, ":ally_casualties", 0),
          (assign, ":enemy_casualties", 0),
          (assign, ":total_allies", 0),
          
          (try_for_agents, ":cur_agent"),
            (agent_is_human, ":cur_agent"),
            (try_begin),
              (agent_is_ally, ":cur_agent"),
              (val_add, ":total_allies", 1),
              (try_begin),
                (neg|agent_is_alive, ":cur_agent"),
                (val_add, ":ally_casualties", 1),
              (try_end),
            (else_try),
              (neg|agent_is_alive, ":cur_agent"),
              (val_add, ":enemy_casualties", 1),
            (try_end),
          (try_end),
          (store_add, ":total_casualties", ":ally_casualties", ":enemy_casualties"),
          (try_begin),
            (gt, ":total_casualties", 0),
            (store_mul, ":morale_adder", ":ally_casualties", 100),
            (val_div, ":morale_adder", ":total_casualties"),
            (val_mul, ":morale_adder", ":ally_casualties"),
            (val_div, ":morale_adder", ":total_allies"),
            (val_mul, ":morale_adder", -30),
            (val_div, ":morale_adder", 100),
            (call_script, "script_change_player_party_morale", ":morale_adder"),
          (try_end),
      ]),
      
      
      
      # script_simulate_battle_with_agents_aux
      # For internal use only
      # Input: arg1 = side (0 = ally, 1 = enemy), arg2 = damage amount
      # Output: none
      ("simulate_battle_with_agents_aux",
        [
          (store_script_param_1, ":attacker_side"),
          (store_script_param_2, ":damage"),
          
          (get_player_agent_no, ":player_agent"),
          (try_for_agents, ":cur_agent"),
            (neq, ":player_agent", ":cur_agent"),
            (agent_is_human, ":cur_agent"),
            (agent_is_alive, ":cur_agent"),
            (try_begin),
              (agent_is_ally, ":cur_agent"),
              (assign, ":cur_agents_side", 0),
            (else_try),
              (assign, ":cur_agents_side", 1),
            (try_end),
            (eq, ":cur_agents_side", ":attacker_side"),
            (agent_get_position, pos2, ":cur_agent"),
            (assign, ":closest_agent", -1),
            (assign, ":min_distance", 100000),
            (try_for_agents, ":cur_agent_2"),
              (agent_is_human, ":cur_agent_2"),
              (agent_is_alive, ":cur_agent_2"),
              (try_begin),
                (agent_is_ally, ":cur_agent_2"),
                (assign, ":cur_agents_side_2", 0),
              (else_try),
                (assign, ":cur_agents_side_2", 1),
              (try_end),
              (this_or_next|neq, ":cur_agent_2", ":player_agent"),
              (eq, "$pin_player_fallen", 0),
              (neq, ":attacker_side", ":cur_agents_side_2"),
              (agent_get_position, pos3, ":cur_agent_2"),
              (get_distance_between_positions, ":cur_distance", pos2, pos3),
              (lt, ":cur_distance", ":min_distance"),
              (assign, ":min_distance", ":cur_distance"),
              (assign, ":closest_agent", ":cur_agent_2"),
            (try_end),
            (ge, ":closest_agent", 0),
            #Fight
            (agent_get_class, ":agent_class", ":cur_agent"),
            (assign, ":agents_speed", 1),
            (assign, ":agents_additional_hit", 0),
            (try_begin),
              (eq, ":agent_class", grc_archers),
              (assign, ":agents_additional_hit", 1),
            (else_try),
              (eq, ":agent_class", grc_cavalry),
              (assign, ":agents_speed", 2),
            (try_end),
            (agent_get_class, ":agent_class", ":closest_agent"),
            (assign, ":agents_speed_2", 1),
            (try_begin),
              (eq, ":agent_class", grc_cavalry),
              (assign, ":agents_speed_2", 3),
            (try_end),
            (assign, ":agents_hit", 10000),
            (val_add, ":min_distance", 2000),
            (val_div, ":agents_hit", ":min_distance"),
            (val_mul, ":agents_hit", 2),# max 8, min 2 hits within 80 meters
            
            (val_mul, ":agents_hit", ":agents_speed"),
            (val_div, ":agents_hit", ":agents_speed_2"),
            (val_add, ":agents_hit", ":agents_additional_hit"),
            
            (assign, ":cur_damage", ":damage"),
            (agent_get_troop_id, ":closest_troop", ":closest_agent"),
            (agent_get_troop_id, ":cur_troop", ":cur_agent"),
            (store_character_level, ":closest_level", ":closest_troop"),
            (store_character_level, ":cur_level", ":cur_troop"),
            (store_sub, ":level_dif", ":cur_level", ":closest_level"),
            (val_add, ":cur_damage", ":level_dif"),
            
            (try_begin),
              (eq, ":closest_agent", ":player_agent"),
              (val_div, ":cur_damage", 2),
              (store_agent_hit_points, ":init_player_hit_points", ":player_agent", 1),
            (try_end),
            
            (try_for_range, ":unused", 0, ":agents_hit"),
              (store_random_in_range, ":random_damage", 0, 100),
              (lt, ":random_damage", ":cur_damage"),
              (agent_deliver_damage_to_agent, ":cur_agent", ":closest_agent"),
            (try_end),
            
            (try_begin),
              (eq, ":closest_agent", ":player_agent"),
              (store_agent_hit_points, ":final_player_hit_points", ":player_agent", 1),
              (store_sub, ":hit_points_difference", ":init_player_hit_points", ":final_player_hit_points"),
              (val_add, "$g_last_mission_player_damage", ":hit_points_difference"),
            (try_end),
            
            (neg|agent_is_alive, ":closest_agent"),
            (try_begin),
              (eq, ":attacker_side", 1),
              (party_add_members, "p_temp_party", ":closest_troop", 1),
              (try_begin),
                (agent_is_wounded, ":closest_agent"),
                (party_wound_members, "p_temp_party", ":closest_troop", 1),
              (try_end),
            (else_try),
              (party_add_members, "p_temp_party_2", ":closest_troop", 1),
              (try_begin),
                (agent_is_wounded, ":closest_agent"),
                (party_wound_members, "p_temp_party_2", ":closest_troop", 1),
              (try_end),
            (try_end),
          (try_end),
      ]),
      
      
      ##  # script_map_get_random_position_around_position_within_range
      ##  # Input: arg1 = minimum_distance in km, arg2 = maximum_distance in km, pos1 = origin position
      ##  # Output: pos2 = result position
      ##  ("map_get_random_position_around_position_within_range",
      ##    [
      ##      (store_script_param_1, ":min_distance"),
      ##      (store_script_param_2, ":max_distance"),
      ##      (val_mul, ":min_distance", 100),
      ##      (assign, ":continue", 1),
      ##      (try_for_range, ":unused", 0, 20),
      ##        (eq, ":continue", 1),
      ##        (map_get_random_position_around_position, pos2, pos1, ":max_distance"),
      ##        (get_distance_between_positions, ":distance", pos2, pos1),
      ##        (ge, ":distance", ":min_distance"),
      ##        (assign, ":continue", 0),
      ##      (try_end),
      ##  ]),
      
      
      # script_get_number_of_unclaimed_centers_by_player
      # Input: none
      # Output: reg0 = number of unclaimed centers, reg1 = last unclaimed center_no
      ("get_number_of_unclaimed_centers_by_player",
        [
          (assign, ":unclaimed_centers", 0),
          (assign, reg1, -1),
          (try_for_range, ":center_no", cities_begin, cities_end),
            (store_faction_of_party, ":faction_no", ":center_no"),
            (eq, ":faction_no", "fac_player_faction"),
            (party_slot_eq, ":center_no", slot_town_claimed_by_player, 0),
            (party_get_num_companion_stacks, ":num_stacks", ":center_no"),
            (ge, ":num_stacks", 1), #castle is garrisoned
            (assign, reg1, ":center_no"),
            (val_add, ":unclaimed_centers", 1),
          (try_end),
          (assign, reg0, ":unclaimed_centers"),
      ]),
      
      # script_troop_count_number_of_enemy_troops
      # Input: arg1 = troop_no
      # Output: reg0 = number_of_enemy_troops
      ("troop_count_number_of_enemy_troops",
        [
          (store_script_param_1, ":troop_no"),
          (assign, ":enemy_count", 0),
          (try_for_range, ":i_enemy_slot", slot_troop_enemies_begin, slot_troop_enemies_end),
            (troop_slot_ge, ":troop_no", ":i_enemy_slot", 1),
            (val_add, ":enemy_count", 1),
          (try_end),
          (assign, reg0, ":enemy_count"),
      ]),
      
      
      # script_cf_troop_check_troop_is_enemy
      # Input: arg1 = troop_no, arg2 = checked_troop_no
      # Output: none (Can fail)
      ("cf_troop_check_troop_is_enemy",
        [
          (store_script_param_1, ":troop_no"),
          (store_script_param_2, ":checked_troop_no"),
          (assign, ":result", 0),
          (try_for_range, ":i_enemy_slot", slot_troop_enemies_begin, slot_troop_enemies_end),
            (troop_slot_eq, ":troop_no", ":i_enemy_slot", ":checked_troop_no"),
            (assign, ":result", 1),
          (try_end),
          (eq, ":result", 1),
      ]),
      
      
      # script_troop_get_leaded_center_with_index
      # Input: arg1 = troop_no, arg2 = center index within range between zero and the number of centers that troop owns
      # Output: reg0 = center_no
      ("troop_get_leaded_center_with_index",
        [
          (store_script_param_1, ":troop_no"),
          (store_script_param_2, ":random_center"),
          (assign, ":result", -1),
          (assign, ":center_count", 0),
          (try_for_range, ":center_no", cities_begin, cities_end),
            (eq, ":result", -1),
            (party_slot_eq, ":center_no", slot_town_lord, ":troop_no"),
            (val_add, ":center_count", 1),
            (gt, ":center_count", ":random_center"),
            (assign, ":result", ":center_no"),
          (try_end),
          (assign, reg0, ":result"),
      ]),
      
      # script_cf_troop_get_random_leaded_center
      # Input: arg1 = troop_no
      # Output: reg0 = center_no (Can fail)
      ("cf_troop_get_random_leaded_center",
        [
          (store_script_param_1, ":troop_no"),
          
          (call_script, "script_get_number_of_hero_centers", ":troop_no"),
          (assign, ":center_count", reg0),
          (store_random_in_range, ":random_center", 0, ":center_count"),
          (call_script, "script_troop_get_leaded_center_with_index", ":troop_no", ":random_center"),
          (neq, reg0, -1),
      ]),
      
      # script_troop_write_owned_centers_to_s2
      # Input: arg1 = troop_no
      # Output: none
      ("troop_write_owned_centers_to_s2",
        [
          (store_script_param_1, ":troop_no"),
          
          (call_script, "script_get_number_of_hero_centers", ":troop_no"),
          (assign, ":no_centers", reg0),
          
          (str_store_troop_name, s5, ":troop_no"),
          
          (try_begin),
            (gt, ":no_centers", 1),
            (try_for_range, ":i_center", 1, ":no_centers"),
              (call_script, "script_troop_get_leaded_center_with_index", ":troop_no", ":i_center"),
              (str_store_party_name_link, s50, reg0),
              (try_begin),
                (eq, ":i_center", 1),
                (call_script, "script_troop_get_leaded_center_with_index", ":troop_no", 0),
                (str_store_party_name_link, s51, reg0),
                (str_store_string, s51, "str_s50_and_s51"),
              (else_try),
                (str_store_string, s51, "str_s50_comma_s51"),
              (try_end),
            (try_end),
            (str_store_string, s2, "str_s5_is_the_ruler_of_s51"),
          (else_try),
            (eq, ":no_centers", 1),
            (call_script, "script_troop_get_leaded_center_with_index", ":troop_no", 0),
            (str_store_party_name_link, s51, reg0),
            (str_store_string, s2, "str_s5_is_the_ruler_of_s51"),
          (else_try),
            (store_troop_faction, ":faction_no", ":troop_no"),
            (str_store_faction_name_link, s6, ":faction_no"),
            (str_store_string, s2, "str_s5_is_a_nobleman_of_s6"),
          (try_end),
      ]),
      
      
      
      
      
      
      # script_complete_family_relations
      # Inputs: none
      # Outputs: none
      
      ("complete_family_relations",
        [
          #Completing family relations
          (try_for_range, ":troop_id", heroes_begin, heroes_end),
            (troop_get_type, ":troop_gender", ":troop_id"),
            (try_begin),
              (troop_get_slot, ":cur_spouse", ":troop_id", slot_troop_spouse),
              (gt, ":cur_spouse", 0),
              (troop_set_slot, ":cur_spouse", slot_troop_spouse, ":troop_id"),
              #Adding children from troop to new spouse
              (troop_get_slot, ":cur_daughter", ":troop_id", slot_troop_daughter),
              (troop_get_slot, ":cur_son", ":troop_id", slot_troop_son),
              (try_begin),
                (gt, ":cur_daughter", 0),
                (troop_set_slot, ":cur_spouse", slot_troop_daughter, ":cur_daughter"),
              (try_end),
              (try_begin),
                (gt, ":cur_son", 0),
                (troop_set_slot, ":cur_spouse", slot_troop_son, ":cur_son"),
              (try_end),
              #Adding children from new spouse to troop
              (troop_get_slot, ":cur_daughter", ":cur_spouse", slot_troop_daughter),
              (troop_get_slot, ":cur_son", ":cur_spouse", slot_troop_son),
              (try_begin),
                (gt, ":cur_daughter", 0),
                (troop_set_slot, ":troop_id", slot_troop_daughter, ":cur_daughter"),
              (try_end),
              (try_begin),
                (gt, ":cur_son", 0),
                (troop_set_slot, ":troop_id", slot_troop_son, ":cur_son"),
              (try_end),
            (try_end),
            (try_begin),
              (troop_get_slot, ":cur_sibling", ":troop_id", slot_troop_sibling),
              (gt, ":cur_sibling", 0),
              (troop_set_slot, ":cur_sibling", slot_troop_sibling, ":troop_id"),
              #Adding parents from troop to new sibling
              (troop_get_slot, ":cur_mother", ":troop_id", slot_troop_mother),
              (troop_get_slot, ":cur_father", ":troop_id", slot_troop_father),
              (try_begin),
                (gt, ":cur_mother", 0),
                (troop_set_slot, ":cur_sibling", slot_troop_mother, ":cur_mother"),
              (try_end),
              (try_begin),
                (gt, ":cur_father", 0),
                (troop_set_slot, ":cur_sibling", slot_troop_father, ":cur_father"),
              (try_end),
              #Adding parents from new sibling to troop
              (troop_get_slot, ":cur_mother", ":cur_sibling", slot_troop_mother),
              (troop_get_slot, ":cur_father", ":cur_sibling", slot_troop_father),
              (try_begin),
                (gt, ":cur_mother", 0),
                (troop_set_slot, ":troop_id", slot_troop_mother, ":cur_mother"),
              (try_end),
              (try_begin),
                (gt, ":cur_father", 0),
                (troop_set_slot, ":troop_id", slot_troop_father, ":cur_father"),
              (try_end),
            (try_end),
            (try_begin),
              (troop_get_slot, ":cur_child", ":troop_id", slot_troop_son),
              (gt, ":cur_child", 0),
              (try_begin),
                (eq, ":troop_gender", 0),
                (troop_set_slot, ":cur_child", slot_troop_father, ":troop_id"),
              (else_try),
                (troop_set_slot, ":cur_child", slot_troop_mother, ":troop_id"),
              (try_end),
              #Adding mother/father and sibling from troop to new son
              (troop_get_slot, ":cur_mother_father", ":troop_id", slot_troop_spouse),
              (troop_get_slot, ":cur_sibling", ":troop_id", slot_troop_daughter),
              (try_begin),
                (gt, ":cur_mother_father", 0),
                (try_begin),
                  (eq, ":troop_gender", 1),
                  (troop_set_slot, ":cur_child", slot_troop_father, ":cur_mother_father"),
                (else_try),
                  (troop_set_slot, ":cur_child", slot_troop_mother, ":cur_mother_father"),
                (try_end),
              (try_end),
              (try_begin),
                (gt, ":cur_sibling", 0),
                (troop_set_slot, ":cur_child", slot_troop_sibling, ":cur_sibling"),
              (try_end),
              #Adding son/daughter and spouse from new son to troop
              (try_begin),
                (eq, ":troop_gender", 0),
                (troop_get_slot, ":cur_spouse", ":cur_child", slot_troop_mother),
              (else_try),
                (troop_get_slot, ":cur_spouse", ":cur_child", slot_troop_father),
              (try_end),
              (troop_get_slot, ":cur_daughter", ":cur_child", slot_troop_sibling),
              (try_begin),
                (gt, ":cur_spouse", 0),
                (troop_set_slot, ":troop_id", slot_troop_spouse, ":cur_spouse"),
              (try_end),
              (try_begin),
                (gt, ":cur_daughter", 0),
                (troop_set_slot, ":troop_id", slot_troop_daughter, ":cur_daughter"),
              (try_end),
            (try_end),
            (try_begin),
              (troop_get_slot, ":cur_child", ":troop_id", slot_troop_daughter),
              (gt, ":cur_child", 0),
              (try_begin),
                (eq, ":troop_gender", 0),
                (troop_set_slot, ":cur_child", slot_troop_father, ":troop_id"),
              (else_try),
                (troop_set_slot, ":cur_child", slot_troop_mother, ":troop_id"),
              (try_end),
              #Adding mother/father and sibling from troop to new daughter
              (troop_get_slot, ":cur_mother_father", ":troop_id", slot_troop_spouse),
              (troop_get_slot, ":cur_sibling", ":troop_id", slot_troop_son),
              (try_begin),
                (gt, ":cur_mother_father", 0),
                (try_begin),
                  (eq, ":troop_gender", 1),
                  (troop_set_slot, ":cur_child", slot_troop_father, ":cur_mother_father"),
                (else_try),
                  (troop_set_slot, ":cur_child", slot_troop_mother, ":cur_mother_father"),
                (try_end),
              (try_end),
              (try_begin),
                (gt, ":cur_sibling", 0),
                (troop_set_slot, ":cur_child", slot_troop_sibling, ":cur_sibling"),
              (try_end),
              #Adding son/daughter and spouse from new daughter to troop
              (try_begin),
                (eq, ":troop_gender", 0),
                (troop_get_slot, ":cur_spouse", ":cur_child", slot_troop_mother),
              (else_try),
                (troop_get_slot, ":cur_spouse", ":cur_child", slot_troop_father),
              (try_end),
              (troop_get_slot, ":cur_son", ":cur_child", slot_troop_sibling),
              (try_begin),
                (gt, ":cur_spouse", 0),
                (troop_set_slot, ":troop_id", slot_troop_spouse, ":cur_spouse"),
              (try_end),
              (try_begin),
                (gt, ":cur_son", 0),
                (troop_set_slot, ":troop_id", slot_troop_son, ":cur_son"),
              (try_end),
            (try_end),
            (try_begin),
              (troop_get_slot, ":cur_father", ":troop_id", slot_troop_father),
              (gt, ":cur_father", 0),
              (try_begin),
                (eq, ":troop_gender", 0),
                (troop_set_slot, ":cur_father", slot_troop_son, ":troop_id"),
              (else_try),
                (troop_set_slot, ":cur_father", slot_troop_daughter, ":troop_id"),
              (try_end),
              #Adding son/daughter and spouse from troop to new father
              (troop_get_slot, ":cur_spouse", ":troop_id", slot_troop_mother),
              (troop_get_slot, ":cur_son_daughter", ":troop_id", slot_troop_sibling),
              (try_begin),
                (gt, ":cur_spouse", 0),
                (troop_set_slot, ":cur_father", slot_troop_spouse, ":cur_spouse"),
              (try_end),
              (try_begin),
                (gt, ":cur_son_daughter", 0),
                (try_begin),
                  (eq, ":troop_gender", 0),
                  (troop_set_slot, ":cur_father", slot_troop_daughter, ":cur_son_daughter"),
                (else_try),
                  (troop_set_slot, ":cur_father", slot_troop_son, ":cur_son_daughter"),
                (try_end),
              (try_end),
              #Adding mother/father and sibling from new father to troop
              (try_begin),
                (eq, ":troop_gender", 0),
                (troop_get_slot, ":cur_sibling", ":cur_father", slot_troop_daughter),
              (else_try),
                (troop_get_slot, ":cur_sibling", ":cur_father", slot_troop_son),
              (try_end),
              (troop_get_slot, ":cur_mother", ":cur_father", slot_troop_spouse),
              (try_begin),
                (gt, ":cur_sibling", 0),
                (troop_set_slot, ":troop_id", slot_troop_sibling, ":cur_sibling"),
              (try_end),
              (try_begin),
                (gt, ":cur_mother", 0),
                (troop_set_slot, ":troop_id", slot_troop_mother, ":cur_mother"),
              (try_end),
            (try_end),
            (try_begin),
              (troop_get_slot, ":cur_mother", ":troop_id", slot_troop_mother),
              (gt, ":cur_mother", 0),
              (try_begin),
                (eq, ":troop_gender", 0),
                (troop_set_slot, ":cur_mother", slot_troop_son, ":troop_id"),
              (else_try),
                (troop_set_slot, ":cur_mother", slot_troop_daughter, ":troop_id"),
              (try_end),
              #Adding son/daughter and spouse from troop to new mother
              (troop_get_slot, ":cur_spouse", ":troop_id", slot_troop_father),
              (troop_get_slot, ":cur_son_daughter", ":troop_id", slot_troop_sibling),
              (try_begin),
                (gt, ":cur_spouse", 0),
                (troop_set_slot, ":cur_mother", slot_troop_spouse, ":cur_spouse"),
              (try_end),
              (try_begin),
                (gt, ":cur_son_daughter", 0),
                (try_begin),
                  (eq, ":troop_gender", 0),
                  (troop_set_slot, ":cur_mother", slot_troop_daughter, ":cur_son_daughter"),
                (else_try),
                  (troop_set_slot, ":cur_mother", slot_troop_son, ":cur_son_daughter"),
                (try_end),
              (try_end),
              #Adding mother/father and sibling from new mother to troop
              (try_begin),
                (eq, ":troop_gender", 0),
                (troop_get_slot, ":cur_sibling", ":cur_mother", slot_troop_daughter),
              (else_try),
                (troop_get_slot, ":cur_sibling", ":cur_mother", slot_troop_son),
              (try_end),
              (troop_get_slot, ":cur_father", ":cur_mother", slot_troop_spouse),
              (try_begin),
                (gt, ":cur_sibling", 0),
                (troop_set_slot, ":troop_id", slot_troop_sibling, ":cur_sibling"),
              (try_end),
              (try_begin),
                (gt, ":cur_father", 0),
                (troop_set_slot, ":troop_id", slot_troop_father, ":cur_father"),
              (try_end),
            (try_end),
          (try_end),
      ]),
      
      # script_collect friendly_parties
      # Fills the party p_collective_friends with the members of parties attached to main_party and ally_party_no
      ("collect_friendly_parties",
        [
          (party_collect_attachments_to_party, "p_main_party", "p_collective_friends"),
          (try_begin),
            (gt, "$g_ally_party", 0),
            (party_collect_attachments_to_party, "$g_ally_party", "p_temp_party"),
            (assign, "$g_move_heroes", 1),
            (call_script, "script_party_add_party", "p_collective_friends", "p_temp_party"),
          (try_end),
      ]),
      
      # script_encounter_calculate_fit
      # Input: arg1 = troop_no
      # Output: none
      ("encounter_calculate_fit",
        [
          #      (assign, "$g_enemy_fit_for_battle_old",  "$g_enemy_fit_for_battle"),
          #      (assign, "$g_friend_fit_for_battle_old", "$g_friend_fit_for_battle"),
          #      (assign, "$g_main_party_fit_for_battle_old", "$g_main_party_fit_for_battle"),
          (call_script, "script_party_count_fit_for_battle", "p_main_party"),
          #     (assign, "$g_main_party_fit_for_battle", reg0),
          (call_script, "script_collect_friendly_parties"),
          (call_script, "script_party_count_fit_for_battle", "p_collective_friends"),
          (assign, "$g_friend_fit_for_battle", reg0),
          
          (try_begin),
            (gt, "$g_ally_party", 0),
            (party_collect_attachments_to_party, "$g_ally_party", "p_collective_ally"),
            #        (call_script, "script_party_count_fit_for_battle", "p_collective_ally"),
            #        (val_add, "$g_friend_fit_for_battle", reg0),
          (try_end),
          
          (party_collect_attachments_to_party, "$g_enemy_party", "p_collective_enemy"),
          (call_script, "script_party_count_fit_for_battle", "p_collective_enemy"),
          (assign, "$g_enemy_fit_for_battle", reg0),
          (assign, reg11, "$g_enemy_fit_for_battle"),
          (assign, reg10, "$g_friend_fit_for_battle"),
      ]),
      
      # script_encounter_init_variables
      # Input: arg1 = troop_no
      # Output: none
      ("encounter_init_variables",
        [
          (assign, "$capture_screen_shown", 0),
          (assign, "$loot_screen_shown", 0),
          (assign, "$thanked_by_ally_leader", 0),
          (assign, "$g_battle_result", 0),
          (assign, "$cant_leave_encounter", 0),
          (assign, "$cant_talk_to_enemy", 0),
          (assign, "$last_defeated_hero", 0),
          (assign, "$last_freed_hero", 0),
          
          (call_script, "script_encounter_calculate_fit"),
          (call_script, "script_party_copy", "p_main_party_backup", "p_main_party"),
          (call_script, "script_party_calculate_strength", "p_main_party"),
          (assign, "$g_starting_strength_main_party", reg0),
          (call_script, "script_party_copy", "p_encountered_party_backup", "p_collective_enemy"),
          (call_script, "script_party_calculate_strength", "p_collective_enemy"),
          (assign, "$g_starting_strength_enemy_party", reg0),
          #      (assign, "$g_starting_strength_ally_party", 0),
          (assign, "$g_strength_contribution_of_player", 100),
          
          (call_script, "script_party_copy", "p_collective_friends_backup", "p_collective_friends"),
          (call_script, "script_party_calculate_strength", "p_collective_friends"),
          (assign, "$g_starting_strength_friends", reg0),
          (try_begin),
			(eq,'$g_starting_strength_friends',0),
			(assign,'$g_starting_strength_friends',1),
		  (try_end),
		  
          (store_mul, "$g_strength_contribution_of_player","$g_starting_strength_main_party", 100), # reduce contribution if we are helping someone.
          (val_div, "$g_strength_contribution_of_player","$g_starting_strength_friends"),
          
			(try_begin),
				(gt, "$g_ally_party", 0),
				(call_script, "script_party_copy", "p_ally_party_backup", "p_collective_ally"),
				(call_script, "script_party_calculate_strength", "p_collective_ally"),
				(assign, "$g_starting_strength_ally_party", reg0),
				(store_add, ":starting_strength_factor_combined","$g_starting_strength_ally_party","$g_starting_strength_main_party"),
				(store_mul, "$g_strength_contribution_of_player","$g_starting_strength_main_party", 80), #reduce contribution if we are helping someone.
				(val_div, "$g_strength_contribution_of_player",":starting_strength_factor_combined"),
			(try_end),
      ]),
      
      # script_calculate_renown_value
      # Input: arg1 = troop_no
      # Output: fills $battle_renown_value
      ("calculate_renown_value",
        [
          (call_script, "script_party_calculate_strength", "p_main_party"),
          (assign, ":main_party_strength", reg0),
          (call_script, "script_party_calculate_strength", "p_collective_enemy"),
          (assign, ":enemy_strength", reg0),
          (call_script, "script_party_calculate_strength", "p_collective_friends"),
          (assign, ":friends_strength", reg0),
          
          (val_add, ":friends_strength", 1),
          (store_mul, ":enemy_strength_ratio", ":enemy_strength", 100),
          (val_div, ":enemy_strength_ratio", ":friends_strength"),
          
          (assign, ":renown_val", ":enemy_strength"),
          (val_mul, ":renown_val", ":enemy_strength_ratio"),
          (val_div, ":renown_val", 100),
          
          (val_mul, ":renown_val", ":main_party_strength"),
          (val_div, ":renown_val",":friends_strength"),
          
          (store_div, "$battle_renown_value", ":renown_val", 5),
          (val_min, "$battle_renown_value", 2500),
          (convert_to_fixed_point, "$battle_renown_value"),
          (store_sqrt, "$battle_renown_value", "$battle_renown_value"),
          (convert_from_fixed_point, "$battle_renown_value"),
          (assign, reg8, "$battle_renown_value"),
          (display_message, "@Renown value for this battle is {reg8}.",0xFFFFFFFF),
      ]),
      
      
      # script_get_first_agent_with_troop_id
      # Input: arg1 = troop_no
      # Output: agent_id
      ("cf_get_first_agent_with_troop_id",
        [
          (store_script_param_1, ":troop_no"),
          #      (store_script_param_2, ":agent_no_to_begin_searching_after"),
          (assign, ":result", -1),
          (try_for_agents, ":cur_agent"),
            (eq, ":result", -1),
            ##        (try_begin),
            ##          (eq, ":cur_agent", ":agent_no_to_begin_searching_after"),
            ##          (assign, ":agent_no_to_begin_searching_after", -1),
            ##        (try_end),
            ##        (eq, ":agent_no_to_begin_searching_after", -1),
            (agent_get_troop_id, ":cur_troop_no", ":cur_agent"),
            (eq, ":cur_troop_no", ":troop_no"),
            (assign, ":result", ":cur_agent"),
          (try_end),
          (assign, reg0, ":result"),
          (neq, reg0, -1),
      ]),
      
      
      # script_cf_team_get_average_position_of_agents_with_type_to_pos1
      # Input: arg1 = team_no, arg2 = class_no (grc_everyone, grc_infantry, grc_cavalry, grc_archers, grc_heroes)
      # Output: none, pos1 = average_position (0,0,0 if there are no matching agents)
      ("cf_team_get_average_position_of_agents_with_type_to_pos1",
        [
          (store_script_param_1, ":team_no"),
          (store_script_param_2, ":class_no"),
          (assign, ":total_pos_x", 0),
          (assign, ":total_pos_y", 0),
          (assign, ":total_pos_z", 0),
          (assign, ":num_agents", 0),
          (set_fixed_point_multiplier, 100),
          (try_for_agents, ":cur_agent"),
            (agent_is_alive, ":cur_agent"),
            (agent_is_human, ":cur_agent"),
            (agent_get_team, ":cur_team_no", ":cur_agent"),
            (eq, ":cur_team_no", ":team_no"),
            (agent_get_class, ":cur_class_no", ":cur_agent"),
            (this_or_next|eq, ":class_no", grc_everyone),
            (eq, ":class_no", ":cur_class_no"),
            (agent_get_position, pos1, ":cur_agent"),
            (position_get_x, ":cur_pos_x", pos1),
            (val_add, ":total_pos_x", ":cur_pos_x"),
            (position_get_y, ":cur_pos_y", pos1),
            (val_add, ":total_pos_y", ":cur_pos_y"),
            (position_get_z, ":cur_pos_z", pos1),
            (val_add, ":total_pos_z", ":cur_pos_z"),
            (val_add, ":num_agents", 1),
          (try_end),
          (gt, ":num_agents", 1),
          (val_div, ":total_pos_x", ":num_agents"),
          (val_div, ":total_pos_y", ":num_agents"),
          (val_div, ":total_pos_z", ":num_agents"),
          (init_position, pos1),
          (position_move_x, pos1, ":total_pos_x"),
          (position_move_y, pos1, ":total_pos_y"),
          (position_move_z, pos1, ":total_pos_z"),
      ]),
      
      # script_print_party_members
      # Input: arg1 = party_no
      # Output: s51 = output string. "noone" if the party is empty
      ("print_party_members",
        [(store_script_param_1, ":party_no"),
          (party_get_num_companion_stacks, ":num_stacks",":party_no"),
          (try_for_range, ":i_stack", 0, ":num_stacks"),
            (party_stack_get_troop_id, ":stack_troop",":party_no",":i_stack"),
            (troop_is_hero, ":stack_troop"),
            (try_begin),
              (eq, ":i_stack", 0),
              (str_store_troop_name, s51, ":stack_troop"),
            (try_end),
            (str_store_troop_name, s50, ":stack_troop"),
            (try_begin),
              (eq, ":i_stack", 1),
              (str_store_string, s51, "str_s50_and_s51"),
            (else_try),
              (gt, ":i_stack", 1),
              (str_store_string, s51, "str_s50_comma_s51"),
            (try_end),
          (try_end),
          (try_begin),
            (eq, ":num_stacks", 0),
            (str_store_string, s51, "str_noone"),
          (try_end),
      ]),
      
      
      # script_change_banners
      # Input: none
      # Output: none
      #("change_banners",
      #  [(party_get_slot, ":cur_leader", "$g_encountered_party", slot_town_lord),
      #    (try_begin),
      #      (gt, ":cur_leader", 0),
      #      (troop_get_slot, ":troop_banner_object", ":cur_leader", slot_troop_banner_scene_prop),
      #      (replace_scene_props, "spr_banner_a", ":troop_banner_object"),
      #    (try_end),
      #]),
      
      # script_describe_relation_to_s63
      # Input: arg1 = relation (-100 .. 100)
      # Output: none
      ("describe_relation_to_s63",
        [(store_script_param_1, ":relation"),
          (store_add, ":normalized_relation", ":relation", 100),
          (val_add, ":normalized_relation", 5),
          (store_div, ":str_offset", ":normalized_relation", 10),
          (store_add, ":str_id", "str_relation_mnus_100",  ":str_offset"),
          (str_store_string, s63, ":str_id"),
      ]),
      
      # script_describe_center_relation_to_s3
      # Input: arg1 = relation (-100 .. 100)
      # Output: none
      ("describe_center_relation_to_s3",
        [(store_script_param_1, ":relation"),
          (store_add, ":normalized_relation", ":relation", 100),
          (val_add, ":normalized_relation", 5),
          (store_div, ":str_offset", ":normalized_relation", 10),
          (store_add, ":str_id", "str_center_relation_mnus_100",  ":str_offset"),
          (str_store_string, s3, ":str_id"),
      ]),
      
      # script_init_town_walkers
      # Input: none
      # Output: none
      
      
      # script_init_town_walker_agents
      # Input: none
      # Output: none
      
      
      # script_tick_town_walkers
      # Input: none
      # Output: none
      
      
      
      # script_set_town_walker_destination
      # Input: arg1 = agent_no
      # Output: none
      
      
      # script_siege_init_ai_and_belfry
      # Input: none
      # Output: none (required for siege mission templates)
      
      
      # script_store_movement_order_name_to_s1
      # Input: arg1 = team_no, arg2 = class_no
      # Output: s1 = order_name
      ("store_movement_order_name_to_s1",
        [(store_script_param_1, ":team_no"),
          (store_script_param_2, ":class_no"),
          (team_get_movement_order, ":cur_order", ":team_no", ":class_no"),
          (try_begin),
            (eq, ":cur_order", mordr_hold),
            (str_store_string, s1, "@Holding"),
          (else_try),
            (eq, ":cur_order", mordr_follow),
            (str_store_string, s1, "@Following"),
          (else_try),
            (eq, ":cur_order", mordr_charge),
            (str_store_string, s1, "@Charging"),
          (else_try),
            (eq, ":cur_order", mordr_advance),
            (str_store_string, s1, "@Advancing"),
          (else_try),
            (eq, ":cur_order", mordr_fall_back),
            (str_store_string, s1, "@Falling Back"),
          (else_try),
            (eq, ":cur_order", mordr_stand_closer),
            (str_store_string, s1, "@Standing Closer"),
          (else_try),
            (eq, ":cur_order", mordr_spread_out),
            (str_store_string, s1, "@Spreading Out"),
          (else_try),
            (eq, ":cur_order", mordr_stand_ground),
            (str_store_string, s1, "@Standing"),
          (else_try),
            (str_store_string, s1, "@N/A"),
          (try_end),
      ]),
      
      # script_store_riding_order_name_to_s1
      # Input: arg1 = team_no, arg2 = class_no
      # Output: s1 = order_name
      ("store_riding_order_name_to_s1",
        [(store_script_param_1, ":team_no"),
          (store_script_param_2, ":class_no"),
          (team_get_riding_order, ":cur_order", ":team_no", ":class_no"),
          (try_begin),
            (eq, ":cur_order", rordr_free),
            (str_store_string, s1, "@Free"),
          (else_try),
            (eq, ":cur_order", rordr_mount),
            (str_store_string, s1, "@Mount"),
          (else_try),
            (eq, ":cur_order", rordr_dismount),
            (str_store_string, s1, "@Dismount"),
          (else_try),
            (str_store_string, s1, "@N/A"),
          (try_end),
      ]),
      
      # script_store_weapon_usage_order_name_to_s1
      # Input: arg1 = team_no, arg2 = class_no
      # Output: s1 = order_name
      ("store_weapon_usage_order_name_to_s1",
        [(store_script_param_1, ":team_no"),
          (store_script_param_2, ":class_no"),
          (team_get_weapon_usage_order, ":cur_order", ":team_no", ":class_no"),
          (try_begin),
            (eq, ":cur_order", wordr_use_any_weapon),
            (str_store_string, s1, "@Any Weapon"),
          (else_try),
            (eq, ":cur_order", wordr_use_blunt_weapons),
            (str_store_string, s1, "@Blunt Weapons"),
          (else_try),
            (str_store_string, s1, "@N/A"),
          (try_end),
      ]),
      
      # script_team_give_order_from_order_panel
      # Input: arg1 = leader_agent_no, arg2 = class_no
      # Output: none
      ("team_give_order_from_order_panel",
        [(store_script_param_1, ":leader_agent_no"),
          (store_script_param_2, ":order"),
          (agent_get_team, ":team_no", ":leader_agent_no"),
          (set_show_messages, 0),
          (try_begin),
            (eq, "$g_formation_infantry_selected", 1),
            (team_give_order, ":team_no", grc_infantry, ":order"),
          (try_end),
          (try_begin),
            (eq, "$g_formation_archers_selected", 1),
            (team_give_order, ":team_no", grc_archers, ":order"),
          (try_end),
          (try_begin),
            (eq, "$g_formation_cavalry_selected", 1),
            (team_give_order, ":team_no", grc_cavalry, ":order"),
          (try_end),
          
          (try_begin),
            (eq, ":order", mordr_hold),
            (agent_get_position, pos1, ":leader_agent_no"),
            (try_begin),
              (eq, "$g_formation_infantry_selected", 1),
              (team_set_order_position, ":team_no", grc_infantry, pos1),
            (try_end),
            (try_begin),
              (eq, "$g_formation_archers_selected", 1),
              (team_set_order_position, ":team_no", grc_archers, pos1),
            (try_end),
            (try_begin),
              (eq, "$g_formation_cavalry_selected", 1),
              (team_set_order_position, ":team_no", grc_cavalry, pos1),
            (try_end),
          (try_end),
          (set_show_messages, 1),
      ]),
      
      
      # script_update_order_panel
      # Input: arg1 = team_no
      # Output: none
      ("update_order_panel",
        [(store_script_param_1, ":team_no"),
          (set_fixed_point_multiplier, 1000),
          
          (assign, ":old_is_infantry_listening", 0),
          (try_begin),
            (class_is_listening_order, ":team_no", grc_infantry),
            (assign, ":old_is_infantry_listening", 1),
          (try_end),
          (assign, ":old_is_archers_listening", 0),
          (try_begin),
            (class_is_listening_order, ":team_no", grc_archers),
            (assign, ":old_is_archers_listening", 1),
          (try_end),
          (assign, ":old_is_cavalry_listening", 0),
          (try_begin),
            (class_is_listening_order, ":team_no", grc_cavalry),
            (assign, ":old_is_cavalry_listening", 1),
          (try_end),
          
          (call_script, "script_store_movement_order_name_to_s1", ":team_no", grc_infantry),
          (overlay_set_text, "$g_presentation_infantry_movement", s1),
          (call_script, "script_store_riding_order_name_to_s1", ":team_no", grc_infantry),
          (overlay_set_text, "$g_presentation_infantry_riding", s1),
          (call_script, "script_store_weapon_usage_order_name_to_s1", ":team_no", grc_infantry),
          (overlay_set_text, "$g_presentation_infantry_weapon_usage", s1),
          (call_script, "script_store_movement_order_name_to_s1", ":team_no", grc_archers),
          (overlay_set_text, "$g_presentation_archers_movement", s1),
          (call_script, "script_store_riding_order_name_to_s1", ":team_no", grc_archers),
          (overlay_set_text, "$g_presentation_archers_riding", s1),
          (call_script, "script_store_weapon_usage_order_name_to_s1", ":team_no", grc_archers),
          (overlay_set_text, "$g_presentation_archers_weapon_usage", s1),
          (call_script, "script_store_movement_order_name_to_s1", ":team_no", grc_cavalry),
          (overlay_set_text, "$g_presentation_cavalry_movement", s1),
          (call_script, "script_store_riding_order_name_to_s1", ":team_no", grc_cavalry),
          (overlay_set_text, "$g_presentation_cavalry_riding", s1),
          (call_script, "script_store_weapon_usage_order_name_to_s1", ":team_no", grc_cavalry),
          (overlay_set_text, "$g_presentation_cavalry_weapon_usage", s1),
          
          (try_begin),
            (eq, ":old_is_infantry_listening", 1),
            (eq, ":old_is_archers_listening", 1),
            (eq, ":old_is_cavalry_listening", 1),
            (team_set_order_listener, ":team_no", grc_everyone),
          (else_try),
            (eq, ":old_is_infantry_listening", 1),
            (team_set_order_listener, ":team_no", grc_infantry),
          (else_try),
            (eq, ":old_is_archers_listening", 1),
            (team_set_order_listener, ":team_no", grc_archers),
          (else_try),
            (eq, ":old_is_cavalry_listening", 1),
            (team_set_order_listener, ":team_no", grc_cavalry),
          (try_end),
          
          (position_set_y, pos1, 660),
          (position_set_x, pos1, 250),
          (overlay_set_position, "$g_presentation_infantry_movement", pos1),
          (position_set_x, pos1, 400),
          (overlay_set_position, "$g_presentation_infantry_riding", pos1),
          (position_set_x, pos1, 550),
          (overlay_set_position, "$g_presentation_infantry_weapon_usage", pos1),
          
          (position_set_y, pos1, 620),
          (position_set_x, pos1, 250),
          (overlay_set_position, "$g_presentation_archers_movement", pos1),
          (position_set_x, pos1, 400),
          (overlay_set_position, "$g_presentation_archers_riding", pos1),
          (position_set_x, pos1, 550),
          (overlay_set_position, "$g_presentation_archers_weapon_usage", pos1),
          
          (position_set_y, pos1, 580),
          (position_set_x, pos1, 250),
          (overlay_set_position, "$g_presentation_cavalry_movement", pos1),
          (position_set_x, pos1, 400),
          (overlay_set_position, "$g_presentation_cavalry_riding", pos1),
          (position_set_x, pos1, 550),
          (overlay_set_position, "$g_presentation_cavalry_weapon_usage", pos1),
      ]),
      
      
      # script_update_agent_position_on_map
      # Input: arg1 = agent_no, pos2 = map_size_pos
      # Output: none
      ("update_agent_position_on_map",
        [(store_script_param_1, ":agent_no"),
          (agent_get_slot, ":agent_overlay", ":agent_no", slot_agent_map_overlay_id),
          
          (get_player_agent_no, ":player_agent"),
          (try_begin),
            (le, ":agent_overlay", 0),
            (set_fixed_point_multiplier, 1000),
            (try_begin),
              (eq, ":agent_no", ":player_agent"),
              (create_mesh_overlay, reg1, "mesh_player_dot"),
              (position_set_x, pos1, 500),
              (position_set_y, pos1, 500),
              (overlay_set_size, reg1, pos1),
            (else_try),
              (create_mesh_overlay, reg1, "mesh_white_dot"),
              (position_set_x, pos1, 200),
              (position_set_y, pos1, 200),
              (overlay_set_size, reg1, pos1),
            (try_end),
            (overlay_set_alpha, reg1, 0x88),
            (agent_set_slot, ":agent_no", slot_agent_map_overlay_id, reg1),
            (assign, ":agent_overlay", reg1),
          (try_end),
          
          (try_begin),
            (neq, ":agent_no", ":player_agent"),
            (agent_get_party_id, ":agent_party", ":agent_no"),
            (try_begin),
              (eq, ":agent_party", "p_main_party"),
              (agent_get_class, ":agent_class", ":agent_no"),
              (try_begin),
                (eq, ":agent_class", grc_infantry),
                (overlay_set_color, ":agent_overlay", 0x8d5220),
              (else_try),
                (eq, ":agent_class", grc_archers),
                (overlay_set_color, ":agent_overlay", 0x34c6e4),
              (else_try),
                (eq, ":agent_class", grc_cavalry),
                (overlay_set_color, ":agent_overlay", 0x569619),
              (try_end),
            (else_try),
              (agent_is_ally, ":agent_no"),
              (overlay_set_color, ":agent_overlay", 0x5555FF),
            (else_try),
              (overlay_set_color, ":agent_overlay", 0xFF0000),
            (try_end),
          (try_end),
          
          (try_begin),
            (eq, ":agent_no", ":player_agent"),
            (agent_get_look_position, pos1, ":agent_no"),
            (position_get_rotation_around_z, ":rot", pos1),
            (init_position, pos10),
            (position_rotate_z, pos10, ":rot"),
            (overlay_set_mesh_rotation, ":agent_overlay", pos10),
            (call_script, "script_convert_3d_pos_to_map_pos"),
          (else_try),
            (agent_get_position, pos1, ":agent_no"),
            (call_script, "script_convert_3d_pos_to_map_pos"),
          (try_end),
          (overlay_set_position, ":agent_overlay", pos0),
      ]),
      
      # script_convert_3d_pos_to_map_pos
      # Input: pos1 = 3d_pos, pos2 = map_size_pos
      # Output: pos0 = map_pos
      ("convert_3d_pos_to_map_pos",
        [(set_fixed_point_multiplier, 1000),
          (position_transform_position_to_local, pos3, pos2, pos1),
          (position_get_x, ":agent_x_pos", pos3),
          (position_get_y, ":agent_y_pos", pos3),
          (val_div, ":agent_x_pos", "$g_battle_map_scale"),
          (val_div, ":agent_y_pos", "$g_battle_map_scale"),
          (set_fixed_point_multiplier, 1000),
          (store_sub, ":map_x", 980, "$g_battle_map_width"),
          (store_sub, ":map_y", 730, "$g_battle_map_height"),
          (val_add, ":agent_x_pos", ":map_x"),
          (val_add, ":agent_y_pos", ":map_y"),
          (position_set_x, pos0, ":agent_x_pos"),
          (position_set_y, pos0, ":agent_y_pos"),
      ]),
      
      # script_update_order_flags_on_map
      # Input: none
      # Output: none
      ("update_order_flags_on_map",
        [(set_fixed_point_multiplier, 1000),
          (get_player_agent_no, ":player_agent"),
          (agent_get_team, ":player_team", ":player_agent"),
          
          (assign, ":old_is_infantry_listening", 0),
          (try_begin),
            (class_is_listening_order, ":player_team", grc_infantry),
            (assign, ":old_is_infantry_listening", 1),
          (try_end),
          (assign, ":old_is_archers_listening", 0),
          (try_begin),
            (class_is_listening_order, ":player_team", grc_archers),
            (assign, ":old_is_archers_listening", 1),
          (try_end),
          (assign, ":old_is_cavalry_listening", 0),
          (try_begin),
            (class_is_listening_order, ":player_team", grc_cavalry),
            (assign, ":old_is_cavalry_listening", 1),
          (try_end),
          
          (get_scene_boundaries, pos2, pos3),
          
          (team_get_movement_order, ":cur_order", ":player_team", grc_infantry),
          (try_begin),
            (eq, ":cur_order", mordr_hold),
            (team_get_order_position, pos1, ":player_team", grc_infantry),
            (call_script, "script_convert_3d_pos_to_map_pos"),
            (overlay_set_alpha, "$g_battle_map_infantry_order_flag", 0xFF),
            (overlay_set_position, "$g_battle_map_infantry_order_flag", pos0),
          (else_try),
            (overlay_set_alpha, "$g_battle_map_infantry_order_flag", 0),
          (try_end),
          (team_get_movement_order, ":cur_order", ":player_team", grc_archers),
          (try_begin),
            (eq, ":cur_order", mordr_hold),
            (team_get_order_position, pos1, ":player_team", grc_archers),
            (call_script, "script_convert_3d_pos_to_map_pos"),
            (overlay_set_alpha, "$g_battle_map_archers_order_flag", 0xFF),
            (overlay_set_position, "$g_battle_map_archers_order_flag", pos0),
          (else_try),
            (overlay_set_alpha, "$g_battle_map_archers_order_flag", 0),
          (try_end),
          (team_get_movement_order, ":cur_order", ":player_team", grc_cavalry),
          (try_begin),
            (eq, ":cur_order", mordr_hold),
            (team_get_order_position, pos1, ":player_team", grc_cavalry),
            (call_script, "script_convert_3d_pos_to_map_pos"),
            (overlay_set_alpha, "$g_battle_map_cavalry_order_flag", 0xFF),
            (overlay_set_position, "$g_battle_map_cavalry_order_flag", pos0),
          (else_try),
            (overlay_set_alpha, "$g_battle_map_cavalry_order_flag", 0),
          (try_end),
          
          (try_begin),
            (eq, ":old_is_infantry_listening", 1),
            (eq, ":old_is_archers_listening", 1),
            (eq, ":old_is_cavalry_listening", 1),
            (team_set_order_listener, ":player_team", grc_everyone),
          (else_try),
            (eq, ":old_is_infantry_listening", 1),
            (team_set_order_listener, ":player_team", grc_infantry),
          (else_try),
            (eq, ":old_is_archers_listening", 1),
            (team_set_order_listener, ":player_team", grc_archers),
          (else_try),
            (eq, ":old_is_cavalry_listening", 1),
            (team_set_order_listener, ":player_team", grc_cavalry),
          (try_end),
      ]),
      
      # script_update_order_panel_checked_classes
      # Input: none
      # Output: none
      ("update_order_panel_checked_classes",
        [(get_player_agent_no, ":player_agent"),
          (agent_get_team, ":player_team", ":player_agent"),
          
          (try_begin),
            (class_is_listening_order, ":player_team", grc_infantry),
            (overlay_set_val, "$g_presentation_obj_4", 1),
            (assign, "$g_formation_infantry_selected", 1),
            (overlay_animate_to_alpha, "$g_presentation_obj_1", 250, 0x44),
          (else_try),
            (overlay_set_val, "$g_presentation_obj_4", 0),
            (assign, "$g_formation_infantry_selected", 0),
            (overlay_animate_to_alpha, "$g_presentation_obj_1", 250, 0),
          (try_end),
          (try_begin),
            (class_is_listening_order, ":player_team", grc_archers),
            (overlay_set_val, "$g_presentation_obj_5", 1),
            (assign, "$g_formation_archers_selected", 1),
            (overlay_animate_to_alpha, "$g_presentation_obj_2", 250, 0x44),
          (else_try),
            (overlay_set_val, "$g_presentation_obj_5", 0),
            (assign, "$g_formation_archers_selected", 0),
            (overlay_animate_to_alpha, "$g_presentation_obj_2", 250, 0),
          (try_end),
          (try_begin),
            (class_is_listening_order, ":player_team", grc_cavalry),
            (overlay_set_val, "$g_presentation_obj_6", 1),
            (assign, "$g_formation_cavalry_selected", 1),
            (overlay_animate_to_alpha, "$g_presentation_obj_3", 250, 0x44),
          (else_try),
            (overlay_set_val, "$g_presentation_obj_6", 0),
            (assign, "$g_formation_cavalry_selected", 0),
            (overlay_animate_to_alpha, "$g_presentation_obj_3", 250, 0),
          (try_end),
      ]),
      
      # script_update_order_panel_statistics_and_map
      # Input: none
      # Output: none
      ("update_order_panel_statistics_and_map", #TODO: Call this in every battle mission template, once per second
        [(set_fixed_point_multiplier, 1000),
          (assign, ":num_us_ready_infantry", 0),
          (assign, ":num_us_ready_archers", 0),
          (assign, ":num_us_ready_cavalry", 0),
          (assign, ":num_us_wounded_infantry", 0),
          (assign, ":num_us_wounded_archers", 0),
          (assign, ":num_us_wounded_cavalry", 0),
          (assign, ":num_us_dead_infantry", 0),
          (assign, ":num_us_dead_archers", 0),
          (assign, ":num_us_dead_cavalry", 0),
          (assign, ":num_allies_ready_men", 0),
          (assign, ":num_allies_wounded_men", 0),
          (assign, ":num_allies_dead_men", 0),
          (assign, ":num_enemies_ready_men", 0),
          (assign, ":num_enemies_wounded_men", 0),
          (assign, ":num_enemies_dead_men", 0),
          
          (get_player_agent_no, ":player_agent"),
          (agent_get_team, ":player_team", ":player_agent"),
          
          (assign, ":old_is_infantry_listening", 0),
          (try_begin),
            (class_is_listening_order, ":player_team", grc_infantry),
            (assign, ":old_is_infantry_listening", 1),
          (try_end),
          (assign, ":old_is_archers_listening", 0),
          (try_begin),
            (class_is_listening_order, ":player_team", grc_archers),
            (assign, ":old_is_archers_listening", 1),
          (try_end),
          (assign, ":old_is_cavalry_listening", 0),
          (try_begin),
            (class_is_listening_order, ":player_team", grc_cavalry),
            (assign, ":old_is_cavalry_listening", 1),
          (try_end),
          
          (get_scene_boundaries, pos2, pos3),
          
          (try_for_agents,":cur_agent"),
            (agent_is_human, ":cur_agent"),
            (agent_get_class, ":agent_class", ":cur_agent"),
            (agent_get_party_id, ":agent_party", ":cur_agent"),
            (agent_get_slot, ":agent_overlay", ":cur_agent", slot_agent_map_overlay_id),
            (try_begin),
              (eq, ":agent_party", "p_main_party"),
              (try_begin),
                (agent_is_alive, ":cur_agent"),
                (call_script, "script_update_agent_position_on_map", ":cur_agent"),
                
                (try_begin),
                  (eq, ":agent_class", grc_infantry),
                  (val_add, ":num_us_ready_infantry", 1),
                (else_try),
                  (eq, ":agent_class", grc_archers),
                  (val_add, ":num_us_ready_archers", 1),
                (else_try),
                  (eq, ":agent_class", grc_cavalry),
                  (val_add, ":num_us_ready_cavalry", 1),
                (try_end),
              (else_try),
                (overlay_set_alpha, ":agent_overlay", 0),
                (agent_is_wounded, ":cur_agent"),
                (try_begin),
                  (eq, ":agent_class", grc_infantry),
                  (val_add, ":num_us_wounded_infantry", 1),
                (else_try),
                  (eq, ":agent_class", grc_archers),
                  (val_add, ":num_us_wounded_archers", 1),
                (else_try),
                  (eq, ":agent_class", grc_cavalry),
                  (val_add, ":num_us_wounded_cavalry", 1),
                (try_end),
              (else_try),
                (try_begin),
                  (eq, ":agent_class", grc_infantry),
                  (val_add, ":num_us_dead_infantry", 1),
                (else_try),
                  (eq, ":agent_class", grc_archers),
                  (val_add, ":num_us_dead_archers", 1),
                (else_try),
                  (eq, ":agent_class", grc_cavalry),
                  (val_add, ":num_us_dead_cavalry", 1),
                (try_end),
              (try_end),
            (else_try),
              (agent_is_ally, ":cur_agent"),
              (try_begin),
                (agent_is_alive, ":cur_agent"),
                (call_script, "script_update_agent_position_on_map", ":cur_agent"),
                (val_add, ":num_allies_ready_men", 1),
              (else_try),
                (overlay_set_alpha, ":agent_overlay", 0),
                (agent_is_wounded, ":cur_agent"),
                (val_add, ":num_allies_wounded_men", 1),
              (else_try),
                (val_add, ":num_allies_dead_men", 1),
              (try_end),
            (else_try),
              (try_begin),
                (agent_is_alive, ":cur_agent"),
                (call_script, "script_update_agent_position_on_map", ":cur_agent"),
                (val_add, ":num_enemies_ready_men", 1),
              (else_try),
                (overlay_set_alpha, ":agent_overlay", 0),
                (agent_is_wounded, ":cur_agent"),
                (val_add, ":num_enemies_wounded_men", 1),
              (else_try),
                (val_add, ":num_enemies_dead_men", 1),
              (try_end),
            (try_end),
          (try_end),
          (assign, reg1, ":num_us_ready_infantry"),
          (assign, reg2, ":num_us_ready_archers"),
          (assign, reg3, ":num_us_ready_cavalry"),
          (store_add, ":num_us_ready_men", ":num_us_ready_infantry", ":num_us_ready_archers"),
          (val_add, ":num_us_ready_men", ":num_us_ready_cavalry"),
          (store_add, ":num_us_wounded_men", ":num_us_wounded_infantry", ":num_us_wounded_archers"),
          (val_add, ":num_us_wounded_men", ":num_us_wounded_cavalry"),
          (store_add, ":num_us_dead_men", ":num_us_dead_infantry", ":num_us_dead_archers"),
          (val_add, ":num_us_dead_men", ":num_us_dead_cavalry"),
          (assign, reg4, ":num_us_ready_men"),
          (assign, reg5, ":num_us_wounded_men"),
          (assign, reg6, ":num_us_dead_men"),
          (assign, reg7, ":num_allies_ready_men"),
          (assign, reg8, ":num_allies_wounded_men"),
          (assign, reg9, ":num_allies_dead_men"),
          (assign, reg10, ":num_enemies_ready_men"),
          (assign, reg11, ":num_enemies_wounded_men"),
          (assign, reg12, ":num_enemies_dead_men"),
          (overlay_set_text, "$g_presentation_obj_7", "@Infantry ({reg1})"),
          (overlay_set_text, "$g_presentation_obj_8", "@Archers ({reg2})"),
          (overlay_set_text, "$g_presentation_obj_9", "@Cavalry ({reg3})"),
          (overlay_set_text, "$g_battle_us_ready", "@{reg4}"),
          (overlay_set_text, "$g_battle_us_wounded", "@{reg5}"),
          (overlay_set_text, "$g_battle_us_dead", "@{reg6}"),
          (overlay_set_text, "$g_battle_allies_ready", "@{reg7}"),
          (overlay_set_text, "$g_battle_allies_wounded", "@{reg8}"),
          (overlay_set_text, "$g_battle_allies_dead", "@{reg9}"),
          (overlay_set_text, "$g_battle_enemies_ready", "@{reg10}"),
          (overlay_set_text, "$g_battle_enemies_wounded", "@{reg11}"),
          (overlay_set_text, "$g_battle_enemies_dead", "@{reg12}"),
          
          (assign, ":stat_position_x", 100),
          (assign, ":stat_position_y", 100),
          (val_add, ":stat_position_x", 150),
          (val_add, ":stat_position_y", 80),
          (position_set_x, pos1, ":stat_position_x"),
          (position_set_y, pos1, ":stat_position_y"),
          (overlay_set_position, "$g_battle_us_ready", pos1),
          (val_add, ":stat_position_x", 150),
          (position_set_x, pos1, ":stat_position_x"),
          (overlay_set_position, "$g_battle_us_wounded", pos1),
          (val_add, ":stat_position_x", 150),
          (position_set_x, pos1, ":stat_position_x"),
          (overlay_set_position, "$g_battle_us_dead", pos1),
          (val_add, ":stat_position_x", -300),
          (val_add, ":stat_position_y", -40),
          (position_set_x, pos1, ":stat_position_x"),
          (position_set_y, pos1, ":stat_position_y"),
          (overlay_set_position, "$g_battle_allies_ready", pos1),
          (val_add, ":stat_position_x", 150),
          (position_set_x, pos1, ":stat_position_x"),
          (overlay_set_position, "$g_battle_allies_wounded", pos1),
          (val_add, ":stat_position_x", 150),
          (position_set_x, pos1, ":stat_position_x"),
          (overlay_set_position, "$g_battle_allies_dead", pos1),
          (val_add, ":stat_position_x", -300),
          (val_add, ":stat_position_y", -40),
          (position_set_x, pos1, ":stat_position_x"),
          (position_set_y, pos1, ":stat_position_y"),
          (overlay_set_position, "$g_battle_enemies_ready", pos1),
          (val_add, ":stat_position_x", 150),
          (position_set_x, pos1, ":stat_position_x"),
          (overlay_set_position, "$g_battle_enemies_wounded", pos1),
          (val_add, ":stat_position_x", 150),
          (position_set_x, pos1, ":stat_position_x"),
          (overlay_set_position, "$g_battle_enemies_dead", pos1),
          
          (call_script, "script_update_order_flags_on_map"),
          
          (try_begin),
            (eq, ":old_is_infantry_listening", 1),
            (eq, ":old_is_archers_listening", 1),
            (eq, ":old_is_cavalry_listening", 1),
            (team_set_order_listener, ":player_team", grc_everyone),
          (else_try),
            (eq, ":old_is_infantry_listening", 1),
            (team_set_order_listener, ":player_team", grc_infantry),
          (else_try),
            (eq, ":old_is_archers_listening", 1),
            (team_set_order_listener, ":player_team", grc_archers),
          (else_try),
            (eq, ":old_is_cavalry_listening", 1),
            (team_set_order_listener, ":player_team", grc_cavalry),
          (try_end),
      ]),
      
      
      # script_consume_food
      # Input: arg1: order of the food to be consumed
      # Output: none
      ("consume_food",
        [(store_script_param, ":selected_food", 1),
          (troop_get_inventory_capacity, ":capacity", "trp_player"),
          (try_for_range, ":cur_slot", 0, ":capacity"),
            (troop_get_inventory_slot, ":cur_item", "trp_player", ":cur_slot"),
            (is_between, ":cur_item", morale_boosters_begin, morale_boosters_end),
            (item_slot_eq, ":cur_item", slot_item_is_checked, 0),
            (item_set_slot, ":cur_item", slot_item_is_checked, 1),
            (val_sub, ":selected_food", 1),
            (lt, ":selected_food", 0),
            (assign, ":capacity", 0),
            (troop_inventory_slot_get_item_amount, ":cur_amount", "trp_player", ":cur_slot"),
            (val_sub, ":cur_amount", 1),
            (troop_inventory_slot_set_item_amount, "trp_player", ":cur_slot", ":cur_amount"),
          (try_end),
      ]),
      
      # script_calculate_troop_score_for_center
      # Input: arg1 = troop_no, arg2 = center_no
      # Output: reg0 = score
      ("calculate_troop_score_for_center",
        [(store_script_param, ":troop_no", 1),
          (store_script_param, ":center_no", 2),
          (assign, ":num_center_points", 1),
          (try_for_range, ":cur_center", cities_begin, cities_end),
            (assign, ":center_owned", 0),
            (try_begin),
              (eq, ":troop_no", "trp_player"),
              (party_slot_eq, ":cur_center", slot_town_lord, stl_reserved_for_player),
              (assign, ":center_owned", 1),
            (try_end),
            (this_or_next|party_slot_eq, ":cur_center", slot_town_lord, ":troop_no"),
            (eq, ":center_owned", 1),
            (try_begin),
              (party_slot_eq, ":cur_center", slot_party_type, spt_town),
              (val_add, ":num_center_points", 4),
            (else_try),
              (party_slot_eq, ":cur_center", slot_party_type, spt_castle),
              (val_add, ":num_center_points", 2),
            (else_try),
              (val_add, ":num_center_points", 1),
            (try_end),
          (try_end),
          (troop_get_slot, ":troop_renown", ":troop_no", slot_troop_renown),
          (store_add, ":score", 500, ":troop_renown"),
          (val_div, ":score", ":num_center_points"),
          (store_random_in_range, ":random", 50, 100),
          (val_mul, ":score", ":random"),
          (try_begin),
            (party_slot_eq, ":center_no", slot_center_last_taken_by_troop, ":troop_no"),
            (val_mul, ":score", 3),
            (val_div, ":score", 2),
          (try_end),
          (assign, reg0, ":score"),
      ]),
      
      
      # script_assign_lords_to_empty_centers
      # Input: none
      # Output: none
      
      
      
      
      #script_do_party_center_trade
      # INPUT: arg1 = party_no, arg2 = center_no, arg3 = percentage_change_in_center
      # OUTPUT: reg0 = total_change
      ("do_party_center_trade",
        [
          (store_script_param, ":party_no", 1),
          (store_script_param, ":center_no", 2),
          (store_script_param, ":percentage_change", 3),
          (assign, ":total_change", 0),
          (store_sub, ":item_to_price_slot", slot_town_trade_good_prices_begin, trade_goods_begin),
          (try_for_range, ":cur_good", trade_goods_begin, trade_goods_end),
            (store_add, ":cur_good_price_slot", ":cur_good", ":item_to_price_slot"),
            (party_get_slot, ":cur_merchant_price", ":party_no", ":cur_good_price_slot"),
            (party_get_slot, ":cur_center_price", ":center_no", ":cur_good_price_slot"),
            (store_sub, ":price_dif", ":cur_merchant_price", ":cur_center_price"),
            (assign, ":cur_change", ":price_dif"),
            (val_abs, ":cur_change"),
            (val_add, ":total_change", ":cur_change"),
            (val_mul, ":cur_change", ":percentage_change"),
            (val_div, ":cur_change", 100),
            (try_begin),
              (lt, ":price_dif", 0),
              (val_mul, ":cur_change", -1),
            (try_end),
            (val_add, ":cur_center_price", ":cur_change"),
            (party_set_slot, ":center_no", ":cur_good_price_slot", ":cur_center_price"),
            (party_set_slot, ":party_no", ":cur_good_price_slot", ":cur_center_price"),
          (try_end),
          (assign, reg0, ":total_change"),
      ]),
      
      #script_player_join_faction
      # INPUT: arg1 = faction_no
      # OUTPUT: none
      ("player_join_faction",
        [
          (store_script_param, ":faction_no", 1),
          (assign,"$players_kingdom",":faction_no"),
          (try_for_range,":other_kingdom",factions_begin,factions_end),
            (try_begin),
              (neq, ":other_kingdom", ":faction_no"),
              (store_relation, ":other_kingdom_reln", ":other_kingdom", ":faction_no"),
            (else_try),
              (store_relation, ":other_kingdom_reln", "fac_player_faction", ":other_kingdom"),
              (val_max, ":other_kingdom_reln", 12),
            (try_end),
            (set_relation,":other_kingdom","fac_player_faction", ":other_kingdom_reln"),
          (try_end),
          (try_for_range, ":cur_center", cities_begin, cities_end),
            #Give center to kingdom if player is the owner
            (party_slot_eq, ":cur_center", slot_town_lord, "trp_player"),
            (party_set_faction, ":cur_center", ":faction_no"),
          (try_end),
          (assign, "$g_player_banner_granted", 1),
      ]),
      
      ##  #script_player_leave_faction
      ##  # INPUT: none
      ##  # OUTPUT: none
      ##  ("player_leave_faction",
      ##    [
      ##      (try_for_range, ":cur_center", cities_begin, cities_end),
      ##        (try_begin),
      ##          (party_slot_eq, ":cur_center", slot_party_type, spt_village),
      ##          (try_begin),
      ##            (party_get_slot, ":bound_town", ":cur_center", slot_village_bound_center),
      ##            (try_begin),
      ##              #Give village to player if player is the owner of its bound town
      ##              (party_slot_eq, ":bound_town", slot_town_lord, "trp_player"),
      ##              (party_set_faction, ":cur_center", "fac_player_faction"),
      ##            (else_try),
      ##              #Give village to kingdom if player is not the owner of its bound town
      ##              (party_slot_eq, ":cur_center", slot_town_lord, "trp_player"),
      ##              (party_set_faction, ":cur_center", "$players_kingdom"),
      ##            (try_end),
      ##          (try_end),
      ##        (else_try),
      ##          #Give center to player if player is the owner
      ##          (party_slot_eq, ":cur_center", slot_town_lord, "trp_player"),
      ##          (party_set_faction, ":cur_center", "fac_player_faction"),
      ##        (try_end),
      ##      (try_end),
      ##      (assign,"$players_kingdom",0),
      ##      ]),
      
      ##  #script_agent_reassign_team
      ##  # INPUT: arg1 = agent_no
      ##  # OUTPUT: none
      ##  ("agent_reassign_team",
      ##    [(store_script_param, ":agent_no", 1),
      ##     (try_begin),
      ##       (agent_is_human, ":agent_no"),
      ##       (agent_get_party_id, ":party_no", ":agent_no"),
      ##       (agent_get_team, ":old_team_no", ":agent_no"),
      ##       (try_begin),
      ##         (eq, ":old_team_no", 0),
      ##         (neq, ":party_no", "p_main_party"),
      ##         (agent_set_team, ":agent_no", 2),
      ##       (try_end),
      ##     (try_end),
      ##      ]),
      
      #script_start_quest
      # INPUT: arg1 = quest_no, arg2 = giver_troop_no, s2 = description_text
      # OUTPUT: none
      
      
      #script_report_quest_troop_positions
      # INPUT: arg1 = quest_no, arg2 = troop_no
      # OUTPUT: none
      ("report_quest_troop_positions",
        [(store_script_param, ":quest_no", 1),
          (store_script_param, ":troop_no", 2),
          (try_begin),
            (call_script, "script_get_information_about_troops_position", ":troop_no", 1),
            (str_store_string, s5, "@At the time quest was given:^{s1}"),
            (add_quest_note_from_sreg, ":quest_no", 4, s5, 1),
          (try_end),
      ]),
      
     #script_update_village_market_towns
      # INPUT: none
      # OUTPUT: none
      ("update_village_market_towns",
        [(try_for_range, ":cur_village", villages_begin, villages_end),
            (store_faction_of_party, ":village_faction", ":cur_village"),
            (assign, ":min_dist", 999999),
            (assign, ":min_dist_town", -1),
            (try_for_range, ":cur_town", towns_begin, towns_end),
              (store_faction_of_party, ":town_faction", ":cur_town"),
              (eq, ":town_faction", ":village_faction"),
              (store_distance_to_party_from_party, ":cur_dist", ":cur_village", ":cur_town"),
              (lt, ":cur_dist", ":min_dist"),
              (assign, ":min_dist", ":cur_dist"),
              (assign, ":min_dist_town", ":cur_town"),
            (try_end),
            (gt, ":min_dist_town", -1),
            (party_set_slot, ":cur_village", slot_village_market_town, ":min_dist_town"),
          (try_end),
      ]),
      
      
      
      
      
      #script_update_ransom_brokers
      # INPUT: none
      # OUTPUT: none
      ("update_ransom_brokers",
        []),
      
      #script_update_tavern_travelers
      # INPUT: none
      # OUTPUT: none
      ("update_tavern_travelers",
        [#(try_for_range, ":town_no", towns_begin, towns_end),
          #  (party_set_slot, ":town_no", slot_center_tavern_traveler, 0),
          #(try_end),
          
          #(try_for_range, ":troop_no", tavern_travelers_begin, tavern_travelers_end),
          #  (store_random_in_range, ":town_no", towns_begin, towns_end),
          #  (party_set_slot, ":town_no", slot_center_tavern_traveler, ":troop_no"),
          #  (assign, ":done", 0),
          #  (try_for_range, ":unused", 0, 5),
          #    (eq, ":done", 0),
          #    (store_random_in_range, ":info_faction", factions_begin, factions_end),
          #    (neq, ":info_faction", "$players_kingdom"),
          #    (party_set_slot, ":town_no", slot_center_traveler_info_faction, ":info_faction"),
          #    (assign, ":done", 1),
          #  (try_end),
          #(try_end),
      ]),
      
      #script_update_tavern_minstels
      # INPUT: none
      # OUTPUT: none
      ("update_tavern_minstels",
        [#(try_for_range, ":town_no", towns_begin, towns_end),
          #   (party_set_slot, ":town_no", slot_center_tavern_minstrel, 0),
          # (try_end),
          #
          # (try_for_range, ":troop_no", tavern_minstrels_begin, tavern_minstrels_end),
          #   (store_random_in_range, ":town_no", towns_begin, towns_end),
          #   (party_set_slot, ":town_no", slot_center_tavern_minstrel, ":troop_no"),
          # (try_end),
      ]),
      
      #script_update_faction_notes
      # INPUT: faction_no
      # OUTPUT: none
      ("update_faction_notes",
        [(store_script_param, ":faction_no", 1),
          (try_begin),
          (is_between, ":faction_no", factions_begin, factions_end),
          (faction_get_slot, ":faction_leader", ":faction_no", slot_faction_leader),
          (str_store_faction_name, s5, ":faction_no"),
          (str_store_troop_name_link, s6, ":faction_leader"),
          (assign, ":num_centers", 0),
          (str_store_string, s8, "@none"),
          (try_for_range_backwards, ":cur_center", cities_begin, villages_end),
            (store_faction_of_party, ":center_faction", ":cur_center"),
            (eq, ":center_faction", ":faction_no"),
            (try_begin),
              (eq, ":num_centers", 0),
              (str_store_party_name_link, s8, ":cur_center"),
            (else_try),
              (eq, ":num_centers", 1),
              (str_store_party_name_link, s7, ":cur_center"),
              (str_store_string, s8, "@{s7} and {s8}"),
            (else_try),
              (str_store_party_name_link, s7, ":cur_center"),
              (str_store_string, s8, "@{s7}, {s8}"),
            (try_end),
            (val_add, ":num_centers", 1),
          (try_end),
          (assign, ":num_members", 0),
          (str_store_string, s10, "@noone"),
          (try_for_range_backwards, ":cur_troop", bushi_begin, bushi_end),
            (store_troop_faction, ":troop_faction", ":cur_troop"),
            (eq, ":troop_faction", ":faction_no"),
            (neq, ":cur_troop", ":faction_leader"),
            (try_begin),
              (eq, ":num_members", 0),
             (str_store_troop_name_link, s10, ":cur_troop"),
           (else_try),
              (eq, ":num_members", 1),
              (str_store_troop_name_link, s9, ":cur_troop"),
              (str_store_string, s10, "@{s9} and {s10}"),
            (else_try),
              (str_store_troop_name_link, s9, ":cur_troop"),
              (str_store_string, s10, "@{s9}, {s10}"),
           (try_end),
            (val_add, ":num_members", 1),
          (try_end),
          (str_store_string, s12, "@noone"),
          (assign, ":num_enemies", 0),
          (try_for_range_backwards, ":cur_faction", 'fac_hosokawa', 'fac_end_fac'),
            (store_relation, ":cur_relation", ":cur_faction", ":faction_no"),
            (le, ":cur_relation", -10),
            (try_begin),
              (eq, ":num_enemies", 0),
              (str_store_faction_name_link, s12, ":cur_faction"),
            (else_try),
              (eq, ":num_enemies", 1),
              (str_store_faction_name_link, s11, ":cur_faction"),
              (str_store_string, s12, "@{s11} and {s12}"),
            (else_try),
              (str_store_faction_name_link, s11, ":cur_faction"),
              (str_store_string, s12, "@{s11}, {s12}"),
            (try_end),
            (val_add, ":num_enemies", 1),
          (try_end),
          (add_faction_note_from_sreg, ":faction_no", 0, "@{s5} is ruled by {s6}.^It occupies {s8}.^Its vassals are {s10}.^{s5} is at war with {s12}.", 0),
          (try_end),
    
      ]),
	  
	  #script_update_faction_traveler_notes
      # INPUT: faction_no
      # OUTPUT: none
      ("update_faction_traveler_notes",
        [#(store_script_param, ":faction_no", 1),
          # (assign, ":total_men", 0),
          # (try_for_parties, ":cur_party"),
          #   (store_faction_of_party, ":center_faction", ":cur_party"),
          #   (eq, ":center_faction", ":faction_no"),
          #   (party_get_num_companions, ":num_men", ":cur_party"),
          #   (val_add, ":total_men", ":num_men"),
          # (try_end),
          # (str_store_faction_name, s5, ":faction_no"),
          # (assign, reg1, ":total_men"),
          # (add_faction_note_from_sreg, ":faction_no", 1, "@{s5} has a strength of {reg1} men in total.", 1),
          (display_message,'@This is script UpdateFactionTravelerNotes'),
      ]),
      
      
      #script_update_troop_notes
      # INPUT: troop_no
      # OUTPUT: none
      ("update_troop_notes",
         [(store_script_param, ":troop_no", 1),
          (str_store_troop_name, s4, ":troop_no"),
          (store_troop_faction, ":troop_faction", ":troop_no"),
          (faction_get_slot, ":faction_leader", ":troop_faction", slot_faction_leader),
          (str_store_troop_name_link, s5, ":faction_leader"),
          (str_store_faction_name_link, s6, ":troop_faction"),
          (assign, reg4, 0),
          (assign, reg6, 0),
          (try_begin),
            (eq, ":troop_faction", "fac_player_faction"),
            (assign, reg6, 1),
          (else_try),
            (eq, ":faction_leader", ":troop_no"),
            (assign, reg4, 1),
          (try_end),
          (assign, ":num_centers", 0),
          (str_store_string, s8, "@nowhere"),
          (try_for_range_backwards, ":cur_center", cities_begin, villages_end),
            (party_slot_eq, ":cur_center", slot_town_shugo, ":troop_no"),
            (try_begin),
              (eq, ":num_centers", 0),
              (str_store_party_name_link, s8, ":cur_center"),
            (else_try),
              (eq, ":num_centers", 1),
              (str_store_party_name_link, s7, ":cur_center"),
              (str_store_string, s8, "@{s7} and {s8}"),
            (else_try),
              (str_store_party_name_link, s7, ":cur_center"),
              (str_store_string, s8, "@{s7}, {s8}"),
            (try_end),
            (val_add, ":num_centers", 1),
          (try_end),
          (troop_get_type, reg3, ":troop_no"),
          (troop_get_slot, reg5, ":troop_no", slot_troop_renown),
          (add_troop_note_from_sreg, ":troop_no", 0, "@{reg6?:{reg4?{s4} is the leader of {s6}.^:{s4} is a vassal of {s5} of {s6}.^}}Renown: {reg5}.^{reg3?Her:His} fiefs are: {s8}.", 0),
          
      ]),
      
      
      #script_update_center_notes
      # INPUT: center_no
      # OUTPUT: none
("update_center_notes",
	[
		(store_script_param, ":center_no", 1),
		(party_get_slot, ":lord_troop", ":center_no", slot_town_shugo),
		(try_begin),
			(ge,':lord_troop',0),
			(store_troop_faction, ":lord_faction", ":lord_troop"),
			(str_store_troop_name_link, s1, ":lord_troop"),
			(try_begin),
				(eq, ":lord_troop", "trp_player"),
				(str_store_faction_name_link, s2, "$players_kingdom"),
			(else_try),
				(str_store_faction_name_link, s2, ":lord_faction"),
			(try_end),
			(add_party_note_from_sreg, ":center_no", 0, "@Owned by {s1} of the {s2}.", 0),
		(else_try),
			(party_get_faction,':lord_faction',':center_no'),
			(str_store_faction_name_link, s2, ":lord_faction"),
			(add_party_note_from_sreg, ":center_no", 0, "@Owned by the {s2}.", 0),
		(try_end),
		]
	),
      
      
      #script_update_center_recon_notes
      # INPUT: center_no
      # OUTPUT: none
      ("update_center_recon_notes",
        [#(store_script_param, ":center_no", 1),
          # (assign, reg4, 0),
          # (try_begin),
          #   (this_or_next|is_between, ":center_no", towns_begin, towns_end),
          #   (is_between, ":center_no", castles_begin, castles_end),
          #   (party_get_slot, ":center_food_store", ":center_no", slot_town_food_stores),
          #   (call_script, "script_center_get_food_consumption", ":center_no"),
          #   (assign, ":food_consumption", reg0),
          #   (store_div, reg6, ":center_food_store", ":food_consumption"),
          #   (assign, reg4, 1),
          # (try_end),
          # (party_collect_attachments_to_party, ":center_no", "p_collective_ally"),
          # (party_get_num_companions, reg5, "p_collective_ally"),
          # (add_party_note_from_sreg, ":center_no", 1, "@Current garrison consists of {reg5} men.{reg4?^Has food stock for {reg6} days.:}", 1),
          (display_message,'@This is script UpdateCenterReconNotes'),
      ]),
      
#script_spawn_bandits
# INPUT: none
# OUTPUT: none
("spawn_bandits",
	[
		(val_add,'$g_bandit_spawn_script_loop_counter',1),
		(try_for_range,':bandit_template','pt_river_pirates','pt_bandit_raiders_a'),
			(try_begin),
				(eq,':bandit_template','pt_river_pirates'),
				(store_num_parties_of_template,':num_bandits','pt_river_pirates'),
				(le,':num_bandits','$max_river_pirates'),
				(store_random_in_range,':bandit_spawn_point','p_river_pirate_spawn_point','p_forest_bandit_spawn_point'),
				(set_spawn_radius,0),
				(spawn_around_party,':bandit_spawn_point','pt_river_pirates'),
				(party_set_ai_behavior,reg0,ai_bhvr_patrol_party),
				(party_set_ai_object,reg0,yodo),
				(party_set_ai_patrol_radius,reg0,20),
				(party_set_slot,reg0,slot_spawn_ai_state,spai_patrolling_around_center),
				(party_set_slot,reg0,slot_spawn_ai_object,yodo),
				(party_set_slot,reg0,slot_spawn_icon,'icon_axeman'),
			(else_try),
				(eq,':bandit_template','pt_bandits'),
				(store_num_parties_of_template,':num_bandits','pt_bandits'),
				(le,':num_bandits','$max_bandits'),
				(store_random_in_range,':patroling',0,2),
				(set_spawn_radius,0),
				(spawn_around_party,'p_bandit_camp','pt_bandits'),
				(assign,':bandit_party',reg0),
				(try_begin),
					(eq,':patroling',true),
					(party_set_ai_behavior,':bandit_party',ai_bhvr_patrol_party),
					(party_set_ai_object,':bandit_party','p_bandit_camp'),
					(party_set_ai_patrol_radius,':bandit_party',20),
					(party_set_slot,':bandit_party',slot_spawn_ai_state,spai_patrolling_around_center),
					(party_set_slot,':bandit_party',slot_spawn_ai_object,'p_bandit_camp'),
				(else_try),
					(eq,':patroling',false),
					(party_set_slot,':bandit_party',slot_spawn_ai_state,spai_undefined),
				(try_end),
				(party_set_slot,':bandit_party',slot_spawn_type,spt_patrol),
				(party_set_slot,':bandit_party',slot_spawn_icon,'icon_axeman'),
			(else_try),
				(eq,':bandit_template','pt_forest_bandits'),
				(assign,':spawn_this_loop','$g_bandit_spawn_script_loop_counter'),
				(val_mod,':spawn_this_loop',2),
				(eq,':spawn_this_loop',0),
				(store_num_parties_of_template,':num_bandits','pt_forest_bandits'),
				(le,':num_bandits','$max_forest_bandits'),
				(set_spawn_radius,0),
				(spawn_around_party,'p_forest_bandit_spawn_point','pt_forest_bandits'),
				(assign,':bandit_party',reg0),
				(party_set_slot,':bandit_party',slot_spawn_ai_state,spai_undefined),
				(party_set_slot,':bandit_party',slot_spawn_type,spt_patrol),
				(party_set_slot,':bandit_party',slot_spawn_icon,'icon_axeman'),
			(else_try),
				(eq,':bandit_template','pt_mountain_bandits'),
				(assign,':spawn_this_loop','$g_bandit_spawn_script_loop_counter'),
				(val_mod,':spawn_this_loop',3),
				(eq,':spawn_this_loop',0),
				(store_num_parties_of_template,':num_bandits','pt_mountain_bandits'),
				(le,':num_bandits','$max_mountain_bandits'),
				(set_spawn_radius,0),
				(spawn_around_party,'p_mountain_bandit_spawn_point','pt_mountain_bandits'),
				(assign,':bandit_party',reg0),
				(party_set_slot,':bandit_party',slot_spawn_ai_state,spai_undefined),
				(party_set_slot,':bandit_party',slot_spawn_type,spt_patrol),
				(party_set_slot,':bandit_party',slot_spawn_icon,'icon_axeman'),
			(else_try),
				(eq,':bandit_template','pt_river_pirates'),
				(assign,':spawn_this_loop','$g_bandit_spawn_script_loop_counter'),
				(val_mod,':spawn_this_loop',4),
				(eq,':spawn_this_loop',0),
				(store_num_parties_of_template,':num_bandits','pt_sea_raiders'),
				(le,':num_bandits','$max_river_pirates'),
				(store_random_in_range,':bandit_spawn_point','p_sea_raider_spawn_point_1','p_spawn_points_end'),
				(set_spawn_radius,0),
				(spawn_around_party,':bandit_spawn_point','pt_sea_raiders'),
				(assign,':bandit_party',reg0),
				(party_set_slot,':bandit_party',slot_spawn_ai_state,spai_undefined),
				(party_set_slot,':bandit_party',slot_spawn_type,spt_patrol),
				(party_set_slot,':bandit_party',slot_spawn_icon,'icon_axeman'),
			(try_end),
		(try_end),
		(try_for_range,':unused',0,3),
			(store_num_parties_of_template,':num_bandits','pt_bandit_raiders_c'),
			(le,':num_bandits','$max_bandit_raiders'),
			(store_random_in_range,':town',cities_begin,villages_end),
			(set_spawn_radius,25),
			(spawn_around_party,':town','pt_bandit_raiders_c'),
			(assign,':bandit_party',reg0),
			(party_set_slot,':bandit_party',slot_spawn_ai_state,spai_undefined),
			(party_set_slot,':bandit_party',slot_spawn_type,spt_patrol),
			(party_set_slot,':bandit_party',slot_spawn_icon,'icon_axeman'),
		(try_end),
		]
	),
      
      #script_count_mission_casualties_from_agents
      # INPUT: none
      # OUTPUT: none
("count_mission_casualties_from_agents",
	[
		(party_clear, "p_player_casualties"),
		(party_clear, "p_enemy_casualties"),
		(party_clear, "p_ally_casualties"),
		# (display_message,'@count_mission_casualties_from_agents is running...',debug_text),
		(assign, "$any_allies_at_the_last_battle", 0),
		(try_for_agents, ":cur_agent"),
			(agent_is_human, ":cur_agent"),
			(agent_get_party_id, ":agent_party", ":cur_agent"),
			(try_begin),
				(neq, ":agent_party", "p_main_party"),
				(agent_is_ally, ":cur_agent"),
				(assign, "$any_allies_at_the_last_battle", 1),
			(try_end),
			(neg|agent_is_alive, ":cur_agent"),
			(agent_get_troop_id, ":agent_troop_id", ":cur_agent"),
			(try_begin),
				(eq, ":agent_party", "p_main_party"),
				(party_add_members, "p_player_casualties", ":agent_troop_id", 1),
				(try_begin),
					(agent_is_wounded, ":cur_agent"),
					(party_wound_members, "p_player_casualties", ":agent_troop_id", 1),
				(try_end),
			(else_try),
				(agent_is_ally, ":cur_agent"),
				(party_add_members, "p_ally_casualties", ":agent_troop_id", 1),
				(try_begin),
					(agent_is_wounded, ":cur_agent"),
					(party_wound_members, "p_ally_casualties", ":agent_troop_id", 1),
				(try_end),
			(else_try),
				(party_add_members, "p_enemy_casualties", ":agent_troop_id", 1),
				(try_begin),
					(agent_is_wounded, ":cur_agent"),
					(party_wound_members, "p_enemy_casualties", ":agent_troop_id", 1),
				(try_end),
			(try_end),
		(try_end),
		# (party_get_num_companions,reg10,'p_player_casualties'),
		# (party_get_num_companions,reg11,'p_ally_casualties'),
		# (party_get_num_companions,reg12,'p_enemy_casualties'),
		# (display_message,'@Player casualties: {reg10}; Ally casualties: {reg11}; Enemy casualties: {reg12}',debug_text),
		]
	),
      
      #script_get_max_skill_of_player_party
      # INPUT: arg1 = skill_no
      # OUTPUT: reg0 = max_skill, reg1 = skill_owner_troop_no
      ("get_max_skill_of_player_party",
        [(store_script_param, ":skill_no", 1),
          (party_get_num_companion_stacks, ":num_stacks","p_main_party"),
          (store_skill_level, ":max_skill", ":skill_no", "trp_player"),
          (assign, ":skill_owner", "trp_player"),
          (try_for_range, ":i_stack", 0, ":num_stacks"),
            (party_stack_get_troop_id, ":stack_troop","p_main_party",":i_stack"),
            (troop_is_hero, ":stack_troop"),
            (neg|troop_is_wounded, ":stack_troop"),
            (store_skill_level, ":cur_skill", ":skill_no", ":stack_troop"),
            (gt, ":cur_skill", ":max_skill"),
            (assign, ":max_skill", ":cur_skill"),
            (assign, ":skill_owner", ":stack_troop"),
          (try_end),
          (assign, reg0, ":max_skill"),
          (assign, reg1, ":skill_owner"),
      ]),
      
      #script_upgrade_hero_party
      # INPUT: arg1 = skill_no
      # OUTPUT: reg0 = max_skill, reg1 = skill_owner_troop_no
      ("upgrade_hero_party",
        [(store_script_param, ":party_no", 1),
          (store_script_param, ":xp_amount", 2),
          (party_upgrade_with_xp, ":party_no",":xp_amount",0),
      ]),
  # script_process_sieges - needs modification
  # Input: none
  # Output: none
  #called from triggers
("process_sieges",
    [
      (try_for_range, ":center_no", hyogo, cities_end),
        (party_get_slot, ":town_food_store", ":center_no", slot_town_food_stores),
        (call_script, "script_center_get_food_store_limit", ":center_no"),
        (assign, ":food_store_limit", reg0),
        (try_begin),
          (party_get_slot, ":besieger_party", ":center_no", slot_town_is_besieged_by),
          (ge, ":besieger_party", 0), #town is under siege
          (store_faction_of_party, ":center_faction", ":center_no"),
          # Lift siege unless there is an enemy party nearby
          (assign, ":siege_lifted", 0),
          (try_begin),
            (store_distance_to_party_from_party, ":besieger_distance", ":center_no", ":besieger_party"),
            (this_or_next|gt, ":besieger_distance", 5),
            (neg|party_is_active, ":besieger_party"),
            (assign, ":siege_lifted", 1),
            (try_for_range, ":enemy_hero", 0, 0), # was kingdom heroes begin and end
              (troop_slot_eq, ":enemy_hero", slot_troop_occupation, slto_kingdom_hero),
              (troop_get_slot, ":enemy_party", ":enemy_hero", slot_troop_leaded_party),
              (ge, ":enemy_party", 0),
              (store_faction_of_party, ":party_faction", ":enemy_party"),
              (store_relation, ":reln", ":party_faction", ":center_faction"),
              (lt, ":reln", 0),
              (store_distance_to_party_from_party, ":distance", ":center_no", ":enemy_party"),
              (lt, ":distance", 4),
              (assign, ":besieger_party", ":enemy_party"),
              (party_set_slot, ":center_no", slot_town_is_besieged_by, ":enemy_party"),
              (assign, ":siege_lifted", 0),
            (try_end),
          (try_end),
          (try_begin),
            (eq, ":siege_lifted", 1),
            (party_set_slot, ":center_no", slot_town_is_besieged_by, -1), #clear siege
            (call_script, "script_village_set_state",  ":center_no", 0), #clear siege flag
            (try_begin),
              (eq, ":center_no", "$g_player_besiege_town"),
              (assign, "$g_siege_method", 0), #remove siege progress
            (try_end),
            (str_store_party_name, s3, ":center_no"),
            #(display_message, "@{s3} is no longer under siege."),
          (else_try),
            (call_script, "script_center_get_food_consumption", ":center_no"),
            (assign, ":food_consumption", reg0),
            (val_sub, ":town_food_store", ":food_consumption"), #reduce food only under siege???
            (try_begin),
              (le, ":town_food_store", 0), #town is starving
              (store_random_in_range, ":r", 0, 100),
              (lt, ":r", 10),
              (call_script, "script_party_wound_all_members", ":center_no"), # town falls with 10% chance if starving
            (try_end),
          (try_end),
        (else_try),
          #town is not under siege...
          (val_add, ":town_food_store", 30), #add 30 food (significant for castles only.
        (try_end),
        
        (val_min, ":town_food_store", ":food_store_limit"),
        (val_max, ":town_food_store", 0),
        (party_set_slot, ":center_no", slot_town_food_stores, ":town_food_store"),
      (try_end),
  ]),
# script_process_village_raids
  # Input: none
  # Output: none
  # called from triggers every three hours
("process_raids",
	[
		(try_for_range, ":town", towns_begin, villages_end),
			(party_get_slot, ":raid_progress", ":town", slot_town_raid_progress),
			(try_begin),
				(party_slot_eq, ":town", slot_town_state, 0), #village is normal
				(val_sub, ":raid_progress", 10),
				(val_max, ":raid_progress", 0),
				(party_set_slot, ":town", slot_town_raid_progress, ":raid_progress"),
			(else_try),
				(party_slot_eq, ":town", slot_town_state, sts_being_raided), #village is being raided
				# End raid unless there is an enemy party nearby
				(assign, ":raid_ended", 1),
				(party_get_slot, ":raider_party", ":town", slot_town_raided_by),
				(try_begin),
					(ge, ":raider_party", 0),
					(party_is_active, ":raider_party"),
					# (this_or_next|neq, ":raider_party", "p_main_party"),
					(eq, "$g_player_is_captive", 0),
					(store_distance_to_party_from_party, ":distance", ":town", ":raider_party"),
					(lt, ":distance", raid_distance),
					(assign, ":raid_ended", 0),
				(try_end),
				(try_begin),
					(eq, ":raid_ended", 1),
					(call_script,'script_object_modify_slot',obj_party,':town',slot_town_state,op_asn,sts_normal),
					(party_set_slot, ":town", slot_town_smoke_added, 0),
					(party_clear_particle_systems, ":town"),
				(else_try),
					(val_add, ":raid_progress", 10),
					(party_set_slot, ":town", slot_town_raid_progress, ":raid_progress"),
					(try_begin),
						(ge, ":raid_progress", 50),
						(party_slot_eq, ":town", slot_town_smoke_added, 0),
						(party_add_particle_system, ":town", "psys_map_village_fire"),
						(party_add_particle_system, ":town", "psys_map_village_fire_smoke"),
						# (party_set_icon, ":town", "icon_village_burnt_a"),
						(party_set_slot, ":town", slot_town_smoke_added, 1),
					(try_end),
					(try_begin),
						(gt, ":raid_progress", 100),
						(str_store_party_name, s1, ":town"),
						(party_get_slot, ":looter_party", ":town", slot_town_raided_by),
						(str_store_party_name, s2, ":looter_party"),
						(display_log_message, "@The village of {s1} has been looted by {s2}."),
						(call_script,'script_object_modify_slot',obj_party,':town',slot_town_state,op_asn,sts_looted),
						(party_set_slot, ":town", slot_town_raid_progress, 0),
						(party_set_slot, ":town", slot_town_recover_progress, 0),
					(try_end),
				(try_end),
			(else_try),
				(party_slot_eq, ":town", slot_town_state, sts_looted), #village is looted
				(party_get_slot, ":recover_progress", ":town", slot_town_recover_progress),
				(val_add, ":recover_progress", 1),
				(party_set_slot, ":town", slot_town_recover_progress, ":recover_progress"), #village looted
				(try_begin),
					(ge, ":recover_progress", 10),
					(party_slot_eq, ":town", slot_town_smoke_added, 1),
					(party_clear_particle_systems, ":town"),
					(party_add_particle_system, ":town", "psys_map_village_looted_smoke"),
					(party_set_slot, ":town", slot_town_smoke_added, 2),
				(try_end),
				(try_begin),
					(gt, ":recover_progress", 50),
					(party_slot_eq, ":town", slot_town_smoke_added, 2),
					(party_clear_particle_systems, ":town"),
					(party_set_slot, ":town", slot_town_smoke_added, 3),
					# (party_set_icon, ":town", "icon_village_deserted_a"),
				(try_end),
				(try_begin),
					(gt, ":recover_progress", 100),
					(call_script,'script_object_modify_slot',obj_party,':town',slot_town_state,op_asn,sts_normal),
					(party_set_slot, ":town", slot_town_recover_progress, 0),
					(party_clear_particle_systems, ":town"),
					(party_set_slot, ":town", slot_town_smoke_added, 0),
					# (party_set_icon, ":town", "icon_village_a"),
				(try_end),
			(try_end),
		(try_end),
		]
	),
###################################################################################################
#
# BEGIN ONIN NO RAN SCRIPTS HERE
#
###################################################################################################

###################################################################################################
#################################### Various functions ####################################################
###################################################################################################
# script_object_modify_slot - the ULTIMATE slot modifying script - it does it ALL!!!!11!11!one!!
('object_modify_slot',
	[
		(store_script_param,':obj_type',1),
		(store_script_param,':obj_no',2),
		(store_script_param,':obj_slot_no',3),
		(store_script_param,':operation',4),
		(store_script_param,':value',5),
		(try_begin),
			(eq,':obj_type',obj_troop),
			(troop_get_slot,':obj_value',':obj_no',':obj_slot_no'),
			(try_begin),
				(eq,':operation',op_asn),
				(assign,':obj_value',':value'),
			(else_try),
				(eq,':operation',op_add),
				(val_add,':obj_value',':value'),
			(else_try),
				(eq,':operation',op_sub),
				(val_sub,':obj_value',':value'),
			(else_try),
				(eq,':operation',op_mul),
				(val_mul,':obj_value',':value'),
			(else_try),
				(eq,':operation',op_div),
				(val_div,':obj_value',':value'),
			(else_try),
				(eq,':operation',op_mod),
				(val_mod,':obj_value',':value'),
			(else_try),
				(eq,':operation',op_min),
				(val_min,':obj_value',':value'),
			(else_try),
				(eq,':operation',op_max),
				(val_max,':obj_value',':value'),
			(try_end),
			(troop_set_slot,':obj_no',':obj_slot_no',':obj_value'),
		(else_try),
			(eq,':obj_type',obj_party),
			(party_get_slot,':obj_value',':obj_no',':obj_slot_no'),
			(try_begin),
				(eq,':operation',op_asn),
				(assign,':obj_value',':value'),
			(else_try),
				(eq,':operation',op_add),
				(val_add,':obj_value',':value'),
			(else_try),
				(eq,':operation',op_sub),
				(val_sub,':obj_value',':value'),
			(else_try),
				(eq,':operation',op_mul),
				(val_mul,':obj_value',':value'),
			(else_try),
				(eq,':operation',op_div),
				(val_div,':obj_value',':value'),
			(else_try),
				(eq,':operation',op_mod),
				(val_mod,':obj_value',':value'),
			(else_try),
				(eq,':operation',op_min),
				(val_min,':obj_value',':value'),
			(else_try),
				(eq,':operation',op_max),
				(val_max,':obj_value',':value'),
			(try_end),
			(party_set_slot,':obj_no',':obj_slot_no',':obj_value'),
		(else_try),
			(eq,':obj_type',obj_party_template),
			(party_template_get_slot,':obj_value',':obj_no',':obj_slot_no'),
			(try_begin),
				(eq,':operation',op_asn),
				(assign,':obj_value',':value'),
			(else_try),
				(eq,':operation',op_add),
				(val_add,':obj_value',':value'),
			(else_try),
				(eq,':operation',op_sub),
				(val_sub,':obj_value',':value'),
			(else_try),
				(eq,':operation',op_mul),
				(val_mul,':obj_value',':value'),
			(else_try),
				(eq,':operation',op_div),
				(val_div,':obj_value',':value'),
			(else_try),
				(eq,':operation',op_mod),
				(val_mod,':obj_value',':value'),
			(else_try),
				(eq,':operation',op_min),
				(val_min,':obj_value',':value'),
			(else_try),
				(eq,':operation',op_max),
				(val_max,':obj_value',':value'),
			(try_end),
			(party_template_set_slot,':obj_no',':obj_slot_no',':obj_value'),
		(else_try),
			(eq,':obj_type',obj_faction),
			(faction_get_slot,':obj_value',':obj_no',':obj_slot_no'),
			(try_begin),
				(eq,':operation',op_asn),
				(assign,':obj_value',':value'),
			(else_try),
				(eq,':operation',op_add),
				(val_add,':obj_value',':value'),
			(else_try),
				(eq,':operation',op_sub),
				(val_sub,':obj_value',':value'),
			(else_try),
				(eq,':operation',op_mul),
				(val_mul,':obj_value',':value'),
			(else_try),
				(eq,':operation',op_div),
				(val_div,':obj_value',':value'),
			(else_try),
				(eq,':operation',op_mod),
				(val_mod,':obj_value',':value'),
			(else_try),
				(eq,':operation',op_min),
				(val_min,':obj_value',':value'),
			(else_try),
				(eq,':operation',op_max),
				(val_max,':obj_value',':value'),
			(try_end),
			(faction_set_slot,':obj_no',':obj_slot_no',':obj_value'),
		(else_try),
			(eq,':obj_type',obj_item),
			(item_get_slot,':obj_value',':obj_no',':obj_slot_no'),
			(try_begin),
				(eq,':operation',op_asn),
				(assign,':obj_value',':value'),
			(else_try),
				(eq,':operation',op_add),
				(val_add,':obj_value',':value'),
			(else_try),
				(eq,':operation',op_sub),
				(val_sub,':obj_value',':value'),
			(else_try),
				(eq,':operation',op_mul),
				(val_mul,':obj_value',':value'),
			(else_try),
				(eq,':operation',op_div),
				(val_div,':obj_value',':value'),
			(else_try),
				(eq,':operation',op_mod),
				(val_mod,':obj_value',':value'),
			(else_try),
				(eq,':operation',op_min),
				(val_min,':obj_value',':value'),
			(else_try),
				(eq,':operation',op_max),
				(val_max,':obj_value',':value'),
			(try_end),
			(item_set_slot,':obj_no',':obj_slot_no',':obj_value'),
		(else_try),
			(eq,':obj_type',obj_quest),
			(quest_get_slot,':obj_value',':obj_no',':obj_slot_no'),
			(try_begin),
				(eq,':operation',op_asn),
				(assign,':obj_value',':value'),
			(else_try),
				(eq,':operation',op_add),
				(val_add,':obj_value',':value'),
			(else_try),
				(eq,':operation',op_sub),
				(val_sub,':obj_value',':value'),
			(else_try),
				(eq,':operation',op_mul),
				(val_mul,':obj_value',':value'),
			(else_try),
				(eq,':operation',op_div),
				(val_div,':obj_value',':value'),
			(else_try),
				(eq,':operation',op_mod),
				(val_mod,':obj_value',':value'),
			(else_try),
				(eq,':operation',op_min),
				(val_min,':obj_value',':value'),
			(else_try),
				(eq,':operation',op_max),
				(val_max,':obj_value',':value'),
			(try_end),
			(quest_set_slot,':obj_no',':obj_slot_no',':obj_value'),
		(else_try),
			(eq,':obj_type',obj_agent),
			(agent_get_slot,':obj_value',':obj_no',':obj_slot_no'),
			(try_begin),
				(eq,':operation',op_asn),
				(assign,':obj_value',':value'),
			(else_try),
				(eq,':operation',op_add),
				(val_add,':obj_value',':value'),
			(else_try),
				(eq,':operation',op_sub),
				(val_sub,':obj_value',':value'),
			(else_try),
				(eq,':operation',op_mul),
				(val_mul,':obj_value',':value'),
			(else_try),
				(eq,':operation',op_div),
				(val_div,':obj_value',':value'),
			(else_try),
				(eq,':operation',op_mod),
				(val_mod,':obj_value',':value'),
			(else_try),
				(eq,':operation',op_min),
				(val_min,':obj_value',':value'),
			(else_try),
				(eq,':operation',op_max),
				(val_max,':obj_value',':value'),
			(try_end),
			(agent_set_slot,':obj_no',':obj_slot_no',':obj_value'),
		(else_try),
			(eq,':obj_type',obj_scene),
			(scene_get_slot,':obj_value',':obj_no',':obj_slot_no'),
			(try_begin),
				(eq,':operation',op_asn),
				(assign,':obj_value',':value'),
			(else_try),
				(eq,':operation',op_add),
				(val_add,':obj_value',':value'),
			(else_try),
				(eq,':operation',op_sub),
				(val_sub,':obj_value',':value'),
			(else_try),
				(eq,':operation',op_mul),
				(val_mul,':obj_value',':value'),
			(else_try),
				(eq,':operation',op_div),
				(val_div,':obj_value',':value'),
			(else_try),
				(eq,':operation',op_mod),
				(val_mod,':obj_value',':value'),
			(else_try),
				(eq,':operation',op_min),
				(val_min,':obj_value',':value'),
			(else_try),
				(eq,':operation',op_max),
				(val_max,':obj_value',':value'),
			(try_end),
			(scene_set_slot,':obj_no',':obj_slot_no',':obj_value'),
		(try_end),
		]
	),
# debug script_print_array
('print_temp_array',
	[
		(store_script_param,':temp_array',1),
		(troop_get_slot,reg10,':temp_array',0),
		(troop_get_slot,reg11,':temp_array',1),
		(troop_get_slot,reg12,':temp_array',2),
		(troop_get_slot,reg13,':temp_array',3),
		(troop_get_slot,reg14,':temp_array',4),
		(troop_get_slot,reg15,':temp_array',5),
		(troop_get_slot,reg16,':temp_array',6),
		(troop_get_slot,reg17,':temp_array',7),
		(str_store_troop_name,s10,':temp_array'),
		(display_message,'@{s10}: {reg10} {reg11} {reg12} {reg13} {reg14} {reg15} {reg16} {reg17}',debug_text),
		]
	),
# script_party_slot_store_add
('party_slot_store_add',
	[
		(store_script_param,':party_no',1),
		(store_script_param,':slot_no',2),
		(store_script_param,':addend_1',3),
		(store_script_param,':addend_2',4),
		(store_add,':result',':addend_1',':addend_2'),
		(party_set_slot,':party_no',':slot_no',':result'),
		]
	),
# script_party_slot_store_sub
('party_slot_store_sub',
	[
		(store_script_param,':party_no',1),
		(store_script_param,':slot_no',2),
		(store_script_param,':addend_1',3),
		(store_script_param,':addend_2',4),
		(store_sub,':result',':addend_1',':addend_2'),
		(party_set_slot,':party_no',':slot_no',':result'),
		]
	),
# script_party_slot_store_mul
('party_slot_store_mul',
	[
		(store_script_param,':party_no',1),
		(store_script_param,':slot_no',2),
		(store_script_param,':addend_1',3),
		(store_script_param,':addend_2',4),
		(store_mul,':result',':addend_1',':addend_2'),
		(party_set_slot,':party_no',':slot_no',':result'),
		]
	),
# script_party_slot_store_div
('party_slot_store_div',
	[
		(store_script_param,':party_no',1),
		(store_script_param,':slot_no',2),
		(store_script_param,':addend_1',3),
		(store_script_param,':addend_2',4),
		(store_div,':result',':addend_1',':addend_2'),
		(party_set_slot,':party_no',':slot_no',':result'),
		]
	),
#script_store_pos
('store_pos',
	[
		(store_script_param,':dest_pos',1),
		(store_script_param,':x_pos',2),
		(store_script_param,':y_pos',3),
		(position_set_x,':dest_pos',':x_pos'),
		(position_set_y,':dest_pos',':y_pos'),
		]
	),
# script_dec2bin
('dec2bin',
	[
		(store_script_param,':dec_value',1),
		(try_for_range,':temp_array_index',0,8),
			(troop_set_slot,'trp_temp_array_a',':temp_array_index',0),
			(troop_set_slot,'trp_temp_array_b',':temp_array_index',0),
			(troop_set_slot,'trp_temp_array_c',':temp_array_index',0),
		(try_end),
		(try_for_range,':loop',0,8),
			(store_sub,':exp',7,':loop'),
			(call_script,'script_store_power',2,':exp'),
			(troop_set_slot,'trp_temp_array_a',':loop',reg0),
		(try_end),
		(try_for_range,':temp_array_index',0,8),
			(troop_get_slot,':bit_num','trp_temp_array_a',':temp_array_index'),
			(assign,':remainder',':dec_value'),
			(val_mod,':remainder',':bit_num'),
			(troop_set_slot,'trp_temp_array_b',':temp_array_index',':remainder'),
		(try_end),
		(store_div,reg0,':dec_value',bit8),
		(troop_set_slot,'trp_temp_array_c',0,reg0),
		(try_for_range,':temp_array_index',1,8),
			(store_sub,':temp_array_index_2',':temp_array_index',1),
			(troop_get_slot,':bit_num','trp_temp_array_a',':temp_array_index'),
			(troop_get_slot,':remainder','trp_temp_array_b',':temp_array_index_2'),
			(store_div,reg0,':remainder',':bit_num'),
			(troop_set_slot,'trp_temp_array_c',':temp_array_index',reg0),
		(try_end),
		(assign,':binary',0),
		(try_for_range,':temp_array_index',0,8),
			(store_sub,':mantissa',7,':temp_array_index'),
			(call_script,'script_store_power',10,':mantissa'),
			(assign,':factor1',reg0),
			(troop_get_slot,':factor2','trp_temp_array_c',':temp_array_index'),
			(store_mul,':addend',':factor1',':factor2'),
			(val_add,':binary',':addend'),
		(try_end),
		(assign,reg0,':binary'),
		]
	),
# script_bin2dec
('bin2dec',
	[
		(store_script_param,':bin_value',1),
		(try_for_range,':temp_array_index',0,8),
			(troop_set_slot,'trp_temp_array_a',':temp_array_index',0),
			(troop_set_slot,'trp_temp_array_b',':temp_array_index',0),
			(troop_set_slot,'trp_temp_array_c',':temp_array_index',0),
		(try_end),
		(try_for_range,':loop',0,8),
			(store_sub,':exp',7,':loop'),
			(call_script,'script_store_power',2,':exp'),
			(troop_set_slot,'trp_temp_array_a',':loop',reg0),
		(try_end),
		(try_for_range,':temp_array_index',0,8),
			(store_sub,':exp',7,':temp_array_index'),
			(call_script,'script_store_power',10,':exp'),
			(assign,':mantissa',reg0),
			(store_div,':bit',':bin_value',':mantissa'),
			(troop_set_slot,'trp_temp_array_c',':temp_array_index',':bit'),
			(val_mod,':bin_value',':mantissa'),
		(try_end),
		(assign,':decimal',0),
		(try_for_range,':temp_array_index',0,8),
			(troop_get_slot,':bit_num','trp_temp_array_a',':temp_array_index'),
			(troop_get_slot,':bit','trp_temp_array_c',':temp_array_index'),
			(store_mul,':addend',':bit',':bit_num'),
			(val_add,':decimal',':addend'),
		(try_end),
		(assign,reg0,':decimal'),
		]
	),
#script_cf_object_flag_set
('cf_object_flag_set',
	[
		(store_script_param,':obj_type',1),
		(store_script_param,':obj_no',2),
		(store_script_param,':obj_slot_no',3),
		(store_script_param,':bit_num',4),
		(try_begin),
			(eq,':obj_type',obj_troop),
			(troop_get_slot,':flags',':obj_no',':obj_slot_no'),
		(else_try),
			(eq,':obj_type',obj_quest),
			(quest_get_slot,':flags',':obj_no',':obj_slot_no'),
		(else_try),
			(eq,':obj_type',obj_party),
			(party_get_slot,':flags',':obj_no',':obj_slot_no'),
		(else_try),
			(eq,':obj_type',obj_party_template),
			(party_template_get_slot,':flags',':obj_no',':obj_slot_no'),
		(else_try),
			(eq,':obj_type',obj_scene),
			(scene_get_slot,':flags',':obj_no',':obj_slot_no'),
		(else_try),
			(eq,':obj_type',obj_agent),
			(agent_get_slot,':flags',':obj_no',':obj_slot_no'),
		(else_try),
			(eq,':obj_type',obj_faction),
			(faction_get_slot,':flags',':obj_no',':obj_slot_no'),
		(else_try),
			(eq,':obj_type',obj_item),
			(item_get_slot,':flags',':obj_no',':obj_slot_no'),
		(try_end),
		(call_script,'script_get_flag_bit',':flags',':bit_num'),
		(eq,reg0,1),
		]
	),
# script_flag32_get_bit
('cf_flag24_bit_set',
	[
		(store_script_param,':flag24',1),
		(store_script_param,':bit_num',2),
		(assign,':divisor_array','trp_temp_array_a'),
		(assign,':mod_value_array','trp_temp_array_b'),
		(assign,':bit_value_array','trp_temp_array_c'),
		(call_script,'script_clear_temp_array',':divisor_array',24),
		(call_script,'script_clear_temp_array',':mod_value_array',24),
		(call_script,'script_clear_temp_array',':bit_value_array',24),
		(try_for_range,':slot_no',0,24),
			(store_mul,':exp',':slot_no',-1),
			(val_add,':exp',23),
			(call_script,'script_store_power',2,':exp'),
			(troop_set_slot,':bit_value_array',':slot_no',reg0),
			(str_store_string,s10,'@{s10} {reg0}'),
		(try_end),
		(troop_get_slot,':bit24',':divisor_array',0),
		(store_div,':bit_value',':flag24',':bit24'),
		(assign,':bit_mod',':flag24'),
		(val_mod,':bit_mod',':bit24'),
		(troop_set_slot,':mod_value_array',0,':bit_mod'),
		(troop_set_slot,':bit_value_array',0,':bit_value'),
		(try_for_range,':slot_no',1,24),
			(store_sub,':prev_slot',':slot_no',1),
			(troop_get_slot,':divisor',':bit_value_array',':slot_no'),
			(troop_get_slot,':prev_mod',':mod_value_array',':prev_slot'),
			(assign,':bit_mod',':prev_mod'),
			(val_mod,':bit_mod',':divisor'),
			(troop_set_slot,':mod_value_array',':slot_no',':bit_mod'),
			(assign,reg10,':bit_mod'),
			(str_store_string,s10,'@{s10} {reg10}'),
		(try_end),
		(try_for_range,':slot_no',1,24),
			(store_sub,':prev_slot',':slot_no',1),
			(troop_get_slot,':divisor',':bit_value_array',':slot_no'),
			(troop_get_slot,':mod_value',':mod_value_array',':prev_slot'),
			(store_div,':bit_value',':mod_value',':divisor'),
			(troop_set_slot,':bit_value_array',':slot_no',':bit_value'),
			(assign,reg10,':bit_value'),
			(str_store_string,s10,'@{s10} {reg10}'),
		(try_end),
		(store_mul,':bit_array_index',':bit_num',-1),
		(val_add,':bit_array_index',24),
		(troop_slot_eq,':bit_value_array',':bit_array_index',1),
		]
	),
# script_flag24_set_bit
('flag24_set_bit',
	[
		(store_script_param,':flag24',1),
		(store_script_param,':bit_num',2),
		(store_script_param,':value',3),
		(assign,':divisor_array','trp_temp_array_a'),
		(assign,':mod_value_array','trp_temp_array_b'),
		(assign,':bit_value_array','trp_temp_array_c'),
		(call_script,'script_clear_temp_array',':divisor_array',24),
		(call_script,'script_clear_temp_array',':mod_value_array',24),
		(call_script,'script_clear_temp_array',':bit_value_array',24),
		# set up divisor array
		(try_for_range,':slot_no',0,24),
			(store_mul,':exp',':slot_no',-1),
			(val_add,':exp',23),
			(call_script,'script_store_power',2,':exp'),
			(troop_set_slot,':bit_value_array',':slot_no',reg0),
		(try_end),
		(troop_get_slot,':bit24',':divisor_array',0),
		(store_div,':bit_value',':flag24',':bit24'),
		(assign,':bit_mod',':flag24'),
		(val_mod,':bit_mod',':bit24'),
		(troop_set_slot,':mod_value_array',0,':bit_mod'),
		(troop_set_slot,':bit_value_array',0,':bit_value'),
		(try_for_range,':slot_no',1,24),
			(store_sub,':prev_slot',':slot_no',1),
			(troop_get_slot,':divisor',':bit_value_array',':slot_no'),
			(troop_get_slot,':prev_mod',':mod_value_array',':prev_slot'),
			(assign,':bit_mod',':prev_mod'),
			(val_mod,':bit_mod',':divisor'),
			(troop_set_slot,':mod_value_array',':slot_no',':bit_mod'),
		(try_end),
		(try_for_range,':slot_no',1,24),
			(store_sub,':prev_slot',':slot_no',1),
			(troop_get_slot,':divisor',':bit_value_array',':slot_no'),
			(troop_get_slot,':mod_value',':mod_value_array',':prev_slot'),
			(store_div,':bit_value',':mod_value',':divisor'),
			(troop_set_slot,':bit_value_array',':slot_no',':bit_value'),
		(try_end),
		(store_mul,':bit_array_index',':bit_num',-1),
		(val_add,':bit_array_index',24),
		(troop_set_slot,':bit_value_array',':bit_array_index',':value'),
		# print bits to stdout
		# (str_clear,s10),
		# (try_for_range,':slot_no',0,24),
			# (troop_get_slot,reg10,':bit_value_array',':slot_no'),
			# (str_store_string,s10,'@{s10} {reg10}'),
		# (try_end),
		# (display_message,'@{s10}',debug_text),
		# reconstitute decimal value
		(assign,':return_flag24',0),
		(str_clear,s10),
		(try_for_range,':slot_no',0,24),
			(store_mul,':exp',':slot_no',-1),
			(val_add,':exp',23),
			(call_script,'script_store_power',2,':exp'),
			(troop_get_slot,':factor',':bit_value_array',':slot_no'),
			(store_mul,':addend',reg0,':factor'),
			(val_add,':return_flag24',':addend'),
		(try_end),
		(assign,reg0,':return_flag24'),
		]
	),
# script_faction_set_possession_flags
('faction_set_possession_flags',
	[
		(store_script_param,':faction',1),
		(store_script_param,':mode',2),
		(try_begin),
			(eq,':mode',0),
			(faction_get_slot,':flags',':faction',slot_faction_city_possession_flags),
			(assign,':start',cities_begin),
			(try_for_range,':town',cities_begin,cities_end),
				(store_faction_of_party,':town_faction',':town'),
				(call_script,'script_cf_faction_is_ally_of_faction',':faction',':town_faction'),
				(store_sub,':bit_num',':town',':start'),
				(val_add,':bit_num',1),
				(call_script,'script_flag24_set_bit',':flags',':bit_num',1),
				(assign,':flags',reg0),
			(try_end),
			(faction_set_slot,':faction',slot_faction_city_possession_flags,':flags'),
		(else_try),
			(eq,':mode',1),
			(faction_get_slot,':flags',':faction',slot_faction_town_possession_flags),
			(assign,':start',towns_begin),
			(try_for_range,':town',towns_begin,towns_end),
				(store_faction_of_party,':town_faction',':town'),
				(call_script,'script_cf_faction_is_ally_of_faction',':faction',':town_faction'),
				(store_sub,':bit_num',':town',':start'),
				(val_add,':bit_num',1),
				(call_script,'script_flag24_set_bit',':flags',':bit_num',1),
				(assign,':flags',reg0),
			(try_end),
			(faction_set_slot,':faction',slot_faction_town_possession_flags,':flags'),
		(else_try),
			(eq,':mode',2),
			(faction_get_slot,':flags',':faction',slot_faction_village_possession_flags_1),
			(assign,':start',villages_begin),
			(try_for_range,':town',villages_begin,villages_midpoint),
				(store_faction_of_party,':town_faction',':town'),
				(call_script,'script_cf_faction_is_ally_of_faction',':faction',':town_faction'),
				(store_sub,':bit_num',':town',':start'),
				(val_add,':bit_num',1),
				(call_script,'script_flag24_set_bit',':flags',':bit_num',1),
				(assign,':flags',reg0),
			(try_end),
			(faction_set_slot,':faction',slot_faction_village_possession_flags_1,':flags'),
		(else_try),
			(eq,':mode',3),
			(faction_get_slot,':flags',':faction',slot_faction_village_possession_flags_2),
			(assign,':start',villages_midpoint),
			(try_for_range,':town',villages_midpoint,villages_end),
				(store_faction_of_party,':town_faction',':town'),
				(call_script,'script_cf_faction_is_ally_of_faction',':faction',':town_faction'),
				(store_sub,':bit_num',':town',':start'),
				(val_add,':bit_num',1),
				(call_script,'script_flag24_set_bit',':flags',':bit_num',1),
				(assign,':flags',reg0),
			(try_end),
			(faction_set_slot,':faction',slot_faction_village_possession_flags_2,':flags'),
		(try_end),
		]
	),
# script_set_flag_bit
('set_flag_bit',
	[
		(store_script_param,':flags',1),
		(store_script_param,':bit_num',2),
		(store_script_param,':value',3),
		(call_script,'script_dec2bin',':flags'),
		# (display_message,'@Flag after dec2bin: {reg0}',debug_text),
		(assign,':bin_flags',reg0),
		(call_script,'script_set_bin_flag_bit',':bin_flags',':bit_num',':value'),
		# (display_message,'@Flag after set_bin_flag_bit: {reg0}',debug_text),
		(assign,':bin_flags',reg0),
		(call_script,'script_bin2dec',':bin_flags'),
		# (display_message,'@Flag after bin2dec: {reg0}',debug_text),
		]
	),
# script_get_flag_bit
('get_flag_bit',
	[
		(store_script_param,':flags',1),
		(store_script_param,':bit_num',2),
		(call_script,'script_dec2bin',':flags'),
		(assign,':bin_flags',reg0),
		(call_script,'script_get_bin_flag_bit',':bin_flags',':bit_num'),
		]
	),
# script_get_bin_flag_bit
('get_bin_flag_bit',
	[
		(store_script_param,':flags',1), # the entire flag value, ex: 10011011 or 00100011
		(store_script_param,':bit_num',2), # the bit place, 1-8
		(try_for_range,':temp_array_index',0,8),
			(call_script,'script_object_modify_slot',obj_troop,'trp_temp_array_a',':temp_array_index',op_asn,0),
			(call_script,'script_object_modify_slot',obj_troop,'trp_temp_array_b',':temp_array_index',op_asn,0),
		(try_end),
		(try_for_range,':temp_array_index',0,8),
			(store_sub,':exp',7,':temp_array_index'),
			(call_script,'script_store_power',10,':exp'),
			(call_script,'script_object_modify_slot',obj_troop,'trp_temp_array_a',':temp_array_index',op_asn,reg0),
		(try_end),
		(try_for_range,':temp_array_index',0,8),
			(troop_get_slot,':divisor','trp_temp_array_a',':temp_array_index'),
			(store_div,':quotient',':flags',':divisor'),
			(val_mod,':quotient',2),
			(call_script,'script_object_modify_slot',obj_troop,'trp_temp_array_b',':temp_array_index',op_asn,':quotient'),
		(try_end),
		(store_mul,':bit_index',':bit_num',-1),
		(val_add,':bit_index',8),
		(troop_get_slot,reg0,'trp_temp_array_b',':bit_index'),
		]
	),
# script_set_bin_flag_bit
('set_bin_flag_bit',
	[
		(store_script_param,':flags',1), # the entire flag value
		(store_script_param,':bit_num',2), # the place of the bit to be set
		(store_script_param,':bit_val',3), # the value to set it to (0 or 1)
		(try_for_range,':temp_array_index',0,8),
			(call_script,'script_object_modify_slot',obj_troop,'trp_temp_array_a',':temp_array_index',op_asn,0),
			(call_script,'script_object_modify_slot',obj_troop,'trp_temp_array_b',':temp_array_index',op_asn,0),
		(try_end),
		(try_for_range,':temp_array_index',0,8),
			(store_sub,':exp',7,':temp_array_index'),
			(call_script,'script_store_power',10,':exp'),
			(call_script,'script_object_modify_slot',obj_troop,'trp_temp_array_a',':temp_array_index',op_asn,reg0),
		(try_end),
		(try_for_range,':temp_array_index',0,8),
			(troop_get_slot,':divisor','trp_temp_array_a',':temp_array_index'),
			(store_div,':quotient',':flags',':divisor'),
			(val_mod,':quotient',2),
			(call_script,'script_object_modify_slot',obj_troop,'trp_temp_array_b',':temp_array_index',op_asn,':quotient'),
		(try_end),
		(store_sub,':bit_index',8,':bit_num'),
		(call_script,'script_object_modify_slot',obj_troop,'trp_temp_array_b',':bit_index',op_asn,':bit_val'),
		(assign,':flags',0), # rebuild full flags value
		(try_for_range,':temp_array_index',0,8),
			(troop_get_slot,':factor1','trp_temp_array_a',':temp_array_index'),
			(troop_get_slot,':factor2','trp_temp_array_b',':temp_array_index'),
			(store_mul,':addend',':factor1',':factor2'),
			(val_add,':flags',':addend'),
		(try_end),
		(assign,reg0,':flags'), # return reconstituted flags value
		]
	),
# script_object_set_flag
('object_set_flag',
	[
		(store_script_param,':obj_type',1),
		(store_script_param,':obj_no',2),
		(store_script_param,':obj_slot_no',3),
		(store_script_param,':bit_num',4),
		(store_script_param,':value',5),
		(try_begin),
			(eq,':obj_type',obj_troop),
			(troop_get_slot,':flags',':obj_no',':obj_slot_no'),
		(else_try),
			(eq,':obj_type',obj_quest),
			(quest_get_slot,':flags',':obj_no',':obj_slot_no'),
		(else_try),
			(eq,':obj_type',obj_party),
			(party_get_slot,':flags',':obj_no',':obj_slot_no'),
		(else_try),
			(eq,':obj_type',obj_party_template),
			(party_template_get_slot,':flags',':obj_no',':obj_slot_no'),
		(else_try),
			(eq,':obj_type',obj_scene),
			(scene_get_slot,':flags',':obj_no',':obj_slot_no'),
		(else_try),
			(eq,':obj_type',obj_agent),
			(agent_get_slot,':flags',':obj_no',':obj_slot_no'),
		(else_try),
			(eq,':obj_type',obj_faction),
			(faction_get_slot,':flags',':obj_no',':obj_slot_no'),
		(else_try),
			(eq,':obj_type',obj_item),
			(item_get_slot,':flags',':obj_no',':obj_slot_no'),
		(try_end),
		(call_script,'script_set_flag_bit',':flags',':bit_num',':value'),
		(assign,':new_flags',reg0),
		(call_script,'script_object_modify_slot',':obj_type',':obj_no',':obj_slot_no',op_asn,':new_flags'),
		],
	),
# script_class_set_rank
('class_set_rank',
	[
		(store_script_param,':array',1),
		(store_script_param,':class',2),
		(store_script_param,':rank_no',3),
		(store_script_param,':pay_rate',4),
		(store_script_param,':fp_rate',5),
		(store_script_param,':renown_to_next_rank',6),
		(store_script_param,':title',7),
		(call_script,'script_array_initialize',8),
		(assign,':rank_data','$return'),
		(call_script,'script_array_push',':rank_data',':class'),
		(call_script,'script_array_push',':rank_data',':rank_no'),
		(call_script,'script_array_push',':rank_data',':pay_rate'),
		(call_script,'script_array_push',':rank_data',':fp_rate'),
		(call_script,'script_array_push',':rank_data',':renown_to_next_rank'),
		(call_script,'script_array_push',':rank_data',':title'),
		(call_script,'script_array_push',':rank_data',0),
		(call_script,'script_array_push',':rank_data',0),
		(call_script,'script_array_push',':array',':rank_data'),
		]
	),
# script_cf_get_progress_to_next_rank
('cf_get_progress_to_next_rank',
	[
		(store_script_param,':rank_array',1),
		(store_script_param,':rank_array_ptr',2),
		(troop_get_slot,':player_renown','trp_player',slot_troop_renown),
		(call_script,'script_array_peek',':rank_array',':rank_array_ptr'),
		(assign,':rank_data_array','$return'),
		(call_script,'script_array_peek',':rank_data_array',slot_renown),
		(assign,':renown_to_next_rank','$return'),
		(ge,':player_renown',':renown_to_next_rank'),
		]
	),
# script_get_rank_pay_and_fp_rate
('get_rank_pay_and_fp_rate',
	[
		(store_script_param,':rank_array',1),
		(store_script_param,':rank_array_ptr',2),
		(call_script,'script_array_peek',':rank_array',':rank_array_ptr'),
		(assign,':rank_data_array','$return'),
		(call_script,'script_array_peek',':rank_data_array',slot_pay_rate),
		(assign,':pay_rate','$return'),
		(call_script,'script_array_peek',':rank_data_array',slot_fp_rate),
		(assign,':fp_rate','$return'),
		(assign,reg0,':pay_rate'),
		(assign,reg1,':fp_rate'),
		]
	),
# script_get_rank_title
('get_rank_title',
	[
		(store_script_param,':rank_array',1),
		(store_script_param,':rank_array_ptr',2),
		(call_script,'script_array_peek',':rank_array',':rank_array_ptr'),
		(assign,':rank_data_array','$return'),
		(call_script,'script_array_peek',':rank_data_array',slot_title),
		(assign,':title','$return'),
		(assign,reg0,':title'),
		]
	),
# script_get_rank_wages
('get_rank_wages',
	[
		(store_script_param,':rank_array',1),
		(store_script_param,':rank_array_ptr',2),
		(call_script,'script_array_peek',':rank_array',':rank_array_ptr'),
		(assign,':rank_data_array','$return'),
		(call_script,'script_array_peek',':rank_data_array',slot_wages),
		(assign,':wages','$return'),
		(assign,reg0,':wages'),
		]
	),
# script_get_rank_fp
('get_rank_fp',
	[
		(store_script_param,':rank_array',1),
		(store_script_param,':rank_array_ptr',2),
		(call_script,'script_array_peek',':rank_array',':rank_array_ptr'),
		(assign,':rank_data_array','$return'),
		(call_script,'script_array_peek',':rank_data_array',slot_fp),
		(assign,':fp','$return'),
		(assign,reg0,':fp'),
		]
	),
# script_get_rank_wages
('set_rank_wages',
	[
		(store_script_param,':rank_array',1),
		(store_script_param,':rank_array_ptr',2),
		(store_script_param,':value',3),
		(call_script,'script_array_peek',':rank_array',':rank_array_ptr'),
		(assign,':rank_data_array','$return'),
		(call_script,'script_array_poke',':rank_data_array',slot_wages,':value'),
		]
	),
# script_get_rank_fp
('set_rank_fp',
	[
		(store_script_param,':rank_array',1),
		(store_script_param,':rank_array_ptr',2),
		(store_script_param,':value',3),
		(call_script,'script_array_peek',':rank_array',':rank_array_ptr'),
		(assign,':rank_data_array','$return'),
		(call_script,'script_array_poke',':rank_data_array',slot_fp,':value'),
		]
	),
# script_wages_add_pay
('wages_add_pay',
	[
		(store_script_param,':rank_array',1),
		(store_script_param,':rank_array_ptr',2),
		(call_script,'script_array_peek',':rank_array',':rank_array_ptr'),
		(assign,':rank_data_array','$return'),
		(call_script,'script_array_peek',':rank_data_array',slot_wages),
		(assign,':wages','$return'),
		(call_script,'script_array_peek',':rank_data_array',slot_fp),
		(assign,':fp','$return'),
		(call_script,'script_get_rank_pay_and_fp_rate',':rank_array',':rank_array_ptr'),
		(assign,':pay_rate',reg0),
		(assign,':fp_rate',reg1),
		(val_add,':wages',':pay_rate'),
		(val_add,':fp',':fp_rate'),
		(call_script,'script_array_poke',':rank_data_array',slot_wages,':wages'),
		(call_script,'script_array_poke',':rank_data_array',slot_fp,':fp'),
		]
	),
# script_store_power
('store_power',
	[
		(store_script_param,':base',1),
		(store_script_param,':exp',2),
		(assign,':result',1),
		(try_for_range,':unused',0,':exp'),
			(store_mul,':product',':base',':result'),
			(assign,':result',':product'),
		(try_end),
		(assign,reg0,':result'),
		]
	),
      #script_post_battle_cleanup
      ('post_battle_cleanup',
        [
          (try_begin),
            (check_quest_active,'qst_ronin_defeat_bandit_parties'),
            (party_get_template_id,':template','$g_encountered_party'),
            (this_or_next|eq,':template','pt_bandits'),
            (this_or_next|eq,':template','pt_forest_bandits'),
            (this_or_next|eq,':template','pt_mountain_bandits'),
            (eq,':template','pt_sea_raiders'),
            (quest_get_slot,reg1,'qst_ronin_defeat_bandit_parties',slot_quest_pt_defeated),
            (val_add,reg1,1),
            (quest_set_slot,'qst_ronin_defeat_bandit_parties',slot_quest_pt_defeated,reg1),
            (quest_get_slot,reg2,'qst_ronin_defeat_bandit_parties',slot_quest_pt_count),
            (val_mul,reg1,100),
            (val_div,reg1,reg2),
            (set_quest_progression,'qst_ronin_defeat_bandit_parties',reg1),
          (try_end),
        ]
      ),
      #script_assign_fame
("assign_fame",
	[
		(store_script_param,':opp_size',1),
		(store_script_param,':opp_fac',2),
		(store_script_param,':plyr_size',3),
		(try_begin),
			(check_quest_active,'qst_faction_hosokawa'),
			(assign,':shugo_enemy_faction','fac_yamana'),
		(else_try),
			(check_quest_active,'qst_faction_yamana'),
			(assign,':shugo_enemy_faction','fac_hosokawa'),
		(try_end),
		(try_begin),
			(eq,":opp_fac",":shugo_enemy_faction"),
			(assign,reg3,1),
		(else_try),
			(eq,":opp_fac","fac_outlaws"),
			(assign,reg3,2),
		(else_try),
			(eq,":opp_fac","fac_innocents"),
			(assign,reg3,-2),
		(else_try),
			(eq,":opp_fac","fac_neutral"),
			(assign,reg3,-1),
		(else_try),
			(eq,":opp_fac","fac_commoners"),
			(assign,reg3,-1),
		(else_try),
			(assign,reg3,1),
		(try_end),
		(assign,reg5,":opp_size"),
		(val_div,reg5,":plyr_size"),
		(try_begin),
			(ge,reg5,5),
			(assign,reg4,5),
		(else_try),
			(eq,reg5,4),
			(assign,reg4,4),
		(else_try),
			(eq,reg5,3),
			(assign,reg4,3),
		(else_try),
			(eq,reg5,2),
			(assign,reg4,2),
		(else_try),
			(le,reg5,1),
			(assign,reg4,1),
		(try_end),
		(assign,reg10,0),
		(val_add,reg10,reg5),
		(val_mul,reg10,reg3),
		(troop_get_slot,reg31,"trp_player",slot_player_renown),
		(val_add,reg31,reg10),
		(troop_set_slot,"trp_player",slot_player_renown,reg31),
		]
	),
# script_get_shugo_faction
# OUTPUT: shugo faction to reg0, enemy faction to reg1
('get_shugo_faction',
	[
		(try_begin),
			(check_quest_active,'qst_faction_hosokawa'),
			(assign,reg0,'fac_hosokawa'),
			(assign,reg1,'fac_yamana'),
		(else_try),
			(check_quest_active,'qst_faction_yamana'),
			(assign,reg0,'fac_yamana'),
			(assign,reg1,'fac_hosokawa'),
		(try_end),
		]
	),
# script_modify_item_durability
# input: item ID, value
# output: none
('modify_item_durability',
	[
		(store_script_param_1,':item'),
		(store_script_param_2,':value'),
		(item_get_slot,':item_durability',':item',slot_item_durability),
		(val_add,':item_durability',':value'),
		(item_set_slot,':item',slot_item_durability,':item_durability'),
		]
	),
      #script assign faction points
      ("assign_fp",
        [
			(store_script_param,':opp_size',1),
			(store_script_param,':opp_fac',2),
			(assign,reg1,":opp_size"),
			(store_relation,reg2,"fac_player_faction",":opp_fac"),
			(try_begin),
				(neq,":opp_fac","fac_outlaws"),
				(lt,reg2,0),
				(val_div,reg1,5),
				(try_begin),
					(eq,reg1,0),
					(assign,reg1,1),
				(try_end),
				(troop_get_slot,reg3,"trp_player",slot_player_faction_points),
				(val_add,reg3,reg1),
				(troop_set_slot,"trp_player",slot_player_faction_points,reg3),
			(try_end),
			]),
      
      #script select_random_faction_village
      ("select_random_faction_village",
        [
          (store_script_param_1,':faction'),
          (try_begin),
            (eq,':faction',"fac_hosokawa"),
            (store_random_party_in_range,'$return','p_village_1','p_village_16'),
          (else_try),
            (eq,':faction',"fac_yamana"),
            (store_random_party_in_range,'$return','p_village_16','p_village_38'),
          (try_end)
        ]
      ),
      #script select_random_faction_town
      ("select_random_faction_town",
        [
          (store_script_param_1,':faction'),
          (try_begin),
            (eq,':faction',"fac_hosokawa"),
            (store_random_party_in_range,'$return','p_town_1','p_town_12'),
          (else_try),
            (eq,':faction',"fac_yamana"),
            (store_random_party_in_range,'$return','p_town_12','p_village_1'),
          (try_end)
        ]
      ),
      #script select_random_faction_city
      ("select_random_faction_city",
        [
          (store_script_param_1,':faction'),
          (try_begin),
            (eq,':faction',"fac_hosokawa"),
            (store_random_party_in_range,'$return','p_city_5','p_city_11'),
          (else_try),
            (eq,':faction',"fac_yamana"),
            (store_random_party_in_range,'$return','p_city_11','p_town_1'),
          (try_end)
        ]
      ),
	  # script_get_random_city
	  ('get_random_city',
		[
			(store_random_in_range,':city',hyogo,all_towns_end),
			(assign,reg0,':city'),
			]
		),
      #script get nearest enemy village
      ('get_nearest_enemy_village',
        [
          (store_script_param_1,':fort'),
          (store_faction_of_party,':fort_fac',':fort'),
          (assign,':dist',10000),
          (try_for_range,':village',villages_begin,villages_end),
            (store_faction_of_party,':village_fac',':village'),
            (call_script,'script_cf_faction_is_ally_of_faction',':fort_fac',':village_fac'),
            (try_begin),
              (eq,'$return',0),
              (store_distance_to_party_from_party,':dist2',':fort',':village'),
              (lt,':dist2',':dist'),
              (val_min,':dist',':dist2'),
              (assign,'$return',':village'),
            (try_end),
          (try_end),
      ]),
      #script is faction ally
      ('cf_faction_is_ally_of_faction',
        [
          (store_script_param_1,':faction'),
          (store_script_param_2,':test_fac'),
          (faction_get_slot,reg1,':faction',slot_faction_hosokawa_ally),
          (faction_get_slot,reg2,':test_fac',slot_faction_hosokawa_ally),
          (try_begin),
            (eq,reg1,reg2),
            (assign,'$return',1),
          (else_try),
            (assign,'$return',0),
          (try_end),
      ]),
      #script check_for_active_patrols
      ("check_for_active_patrols",
        [
          (try_for_range,':town',hyogo,all_towns_end),
            (party_slot_eq,':town',slot_town_patrol_active,1),
            (party_get_slot,':patrol',':town',slot_town_patrol),
            (neg|party_is_active,':patrol'),
            (party_set_slot,':town',slot_town_patrol_active,0),
          (try_end),
          (try_for_parties,':fort'),
            (party_get_template_id,':template',':fort'),
            (eq,':template','pt_fort'),
            (party_slot_eq,':fort',slot_castle_patrol_active,1),
            (party_get_slot,':fort_patrol',':fort',slot_castle_patrol),
            (neg|party_is_active,':fort_patrol'),
            (party_set_slot,':fort',slot_castle_patrol_active,0),
          (try_end),
      ]),
	  # script_update_active_merchants
	  ('update_active_merchants',
		[
			(assign,':num_farmer_parties',0),
			(assign,':num_peddler_parties',0),
			(try_for_parties,':party'),
				(party_get_template_id,':template',':party'),
				(try_begin),
					(eq,':template','pt_traveling_farmers'),
					(val_add,':num_farmer_parties',1),
				(else_try),
					(eq,':template','pt_traveling_peddler'),
					(val_add,':num_peddler_parties',1),
				(try_end),
			(try_end),
			(assign,'$g_num_active_traveling_farmers',':num_farmer_parties'),
			(assign,'$g_num_active_traveling_merchants',':num_peddler_parties'),
			],
		),
      #script award xp
      ("award_xp",
        [
          (store_script_param_1,':size'),
          (store_mul,':gold',':size',10),
          (party_get_num_companion_stacks,':num_stacks','p_main_party'),
          (try_for_range,':i',0,':num_stacks'),
            (party_stack_get_troop_id,':troop_id','p_main_party',':i'),
            (troop_is_hero,':troop_id'),
            (add_xp_to_troop,':size',':troop_id'),
            (troop_add_gold,':troop_id',':gold'),
          (try_end),
      ]),
      
      # script get_caravan_destination
      ('get_caravan_destination',
        [
          (store_script_param_1,':input_town'),
          (party_get_slot,reg41,':input_town',slot_town_caravan_dest_1),
          (party_get_slot,reg42,':input_town',slot_town_caravan_dest_2),
          (party_get_slot,reg43,':input_town',slot_town_caravan_dest_3),
          (shuffle_range,41,44),
          (try_begin),
            (eq,reg41,-1),
            (call_script,'script_get_caravan_destination',':input_town'),
          (try_end),
          (assign,reg0,reg41),
      ]),
      #script reset quest registers
      ("reset_quest_registers",
        [
          (store_script_param,':input_quest',1),
		  # (quest_get_slot,':quest_giver',':input_quest',slot_quest_giver),
		  # (troop_set_slot,':quest_giver',slot_troop_quest,null),
          (try_for_range,reg1,slot_quest_giver,slot_quest_end),
            (quest_set_slot,':input_quest',reg1,null),
          (try_end),
		  
		  ]
      ),
      #script add fame
      ("modify_fame",
        [
          (store_script_param,':input_fame',1),
          (troop_get_slot,reg1,0,slot_player_renown),
          (val_add,reg1,':input_fame'),
          (troop_set_slot,0,slot_player_renown,reg1)]),
# script_init_position
('init_position',
	[
		(store_script_param,':pos_x',1),
		(store_script_param,':pos_y',2),
		(position_set_x,pos0,':pos_x'),
		(position_set_y,pos0,':pos_y'),
		]
	),
# script_ modify_za_standing
('modify_za_standing',
	[
		(store_script_param,':za',1),
		(store_script_param,':value',2),
		(quest_get_slot,':za_standing',':za',slot_quest_za_player_standing),
		(val_add,':za_standing',':value'),
		(quest_set_slot,':za',slot_quest_za_player_standing,':za_standing'),
		]
	),
      #script moidfy town fame
      ("modify_town_fame",
        [
          (store_script_param,':town',1),
          (store_script_param,':input_fame',2),
          (party_get_slot,reg1,':town',slot_town_player_relation),
          (val_add,reg1,':input_fame'),
          (party_set_slot,':town',slot_town_player_relation,reg1)]),
      #script add faction fame
      ("add_faction_fame",
        [
          (store_script_param,':input_fame',1),
          (troop_get_slot,reg1,0,slot_player_renown),
          (val_add,reg1,':input_fame'),
          (troop_set_slot,0,slot_player_renown,reg1)]),
      #script sub faction fame
      ("sub_faction_fame",
        [
          (store_script_param_1,':input_fame'),
          (troop_get_slot,reg1,0,slot_player_renown),
          (val_sub,reg1,':input_fame'),
          (troop_set_slot,0,slot_player_renown,reg1)]),
      #script add faction points
      ("add_faction_points",
        [
          (store_script_param_1,':input_fp'),
          (troop_get_slot,reg1,0,slot_player_faction_points),
          (val_add,reg1,':input_fp'),
          (troop_set_slot,0,slot_player_faction_points,reg1)]),
      #script sub faction points
      ("sub_faction_points",
        [
          (store_script_param_1,':input_fp'),
          (troop_get_slot,reg1,0,slot_player_faction_points),
          (val_sub,reg1,':input_fp'),
          (troop_set_slot,0,slot_player_faction_points,reg1)]),
      #script copy town properties
      ('copy_town_properties',
        [
          (store_script_param_1,':input_city'),
          (store_script_param_2,':input_slot'),
          (party_get_slot,reg1,':input_city',':input_slot'),
          (party_set_slot,'p_dummy',':input_slot',reg1),
        ]
      ),
      #script get town properties
      ("get_town_properties",
        [
          (store_script_param,':input_city',1),
          (call_script,'script_copy_town_properties',':input_city',slot_town_center),
          (call_script,'script_copy_town_properties',':input_city',slot_town_castle),
          (call_script,'script_copy_town_properties',':input_city',slot_town_store),
          (call_script,'script_copy_town_properties',':input_city',slot_town_inn),
          (call_script,'script_copy_town_properties',':input_city',slot_town_smithy),
          (call_script,'script_copy_town_properties',':input_city',slot_town_kokujin),
          (call_script,'script_copy_town_properties',':input_city',slot_town_innkeeper),
          (call_script,'script_copy_town_properties',':input_city',slot_town_merchant),
          (call_script,'script_copy_town_properties',':input_city',slot_town_weaponsmith),
          (call_script,'script_copy_town_properties',':input_city',slot_town_armorer),
          (call_script,'script_copy_town_properties',':input_city',slot_town_export_good),
          (call_script,'script_copy_town_properties',':input_city',slot_town_export_rate),
          (call_script,'script_copy_town_properties',':input_city',slot_town_import_good),
          (call_script,'script_copy_town_properties',':input_city',slot_town_import_rate),
          (call_script,'script_copy_town_properties',':input_city',slot_town_terrain),
          (call_script,'script_copy_town_properties',':input_city',slot_town_size),
          (call_script,'script_copy_town_properties',':input_city',slot_town_mercs),
          (call_script,'script_copy_town_properties',':input_city',slot_town_trade_hub),
          (call_script,'script_copy_town_properties',':input_city',slot_town_trade_dest),
          (call_script,'script_copy_town_properties',':input_city',slot_town_trade_month),
          (call_script,'script_copy_town_properties',':input_city',slot_town_att_to_player),
          (call_script,'script_copy_town_properties',':input_city',slot_town_player_relation),
          (call_script,'script_copy_town_properties',':input_city',slot_town_import_demand),
          (call_script,'script_copy_town_properties',':input_city',slot_town_export_demand),
      ]),
# script list party troops
("list_party_troops",
	[
		(store_script_param_1,':input_party'),
		(try_begin),
			(assign,':temp_array_index',0),
			(try_for_range,':troop_no',"trp_player","trp_last_troop"),
				(party_count_companions_of_type,':troop_no_cnt',':input_party',':troop_no'),
				(try_begin),
					(gt,':troop_no_cnt',0),
					(troop_set_slot,"trp_last_troop",':temp_array_index',':troop_no'),
				(else_try),
					(troop_set_slot,"trp_last_troop",':temp_array_index',0),
				(try_end),
				(val_add,':temp_array_index',1),
			(try_end),
		(try_end)
		]
	),
# script_position_add_x
('position_add_x',
	[
		(store_script_param,':pos',1),
		(store_script_param,':displacement',2),
		(store_script_param,':clamp',3),
		(store_script_param,':lower_bound',4),
		(store_script_param,':upper_bound',5),
		(position_get_x,':pos_x',':pos'),
		(val_add,':pos_x',':displacement'),
		(try_begin),
			(eq,':clamp',true),
			(val_clamp,':pos_x',':lower_bound',':upper_bound'),
		(try_end),
		(position_set_x,':pos',':pos_x'),
		(copy_position,pos0,':pos'),
		]
	),
# script_position_add_y
('position_add_y',
	[
		(store_script_param,':pos',1),
		(store_script_param,':displacement',2),
		(store_script_param,':clamp',3),
		(store_script_param,':lower_bound',4),
		(store_script_param,':upper_bound',5),
		(position_get_y,':pos_y',':pos'),
		(val_add,':pos_y',':displacement'),
		(try_begin),
			(eq,':clamp',true),
			(val_clamp,':pos_y',':lower_bound',':upper_bound'),
		(try_end),
		(position_set_y,':pos',':pos_y'),
		(copy_position,pos0,':pos'),
		]
	),
# script_position_add_z
('position_add_z',
	[
		(store_script_param,':pos',1),
		(store_script_param,':displacement',2),
		(store_script_param,':clamp',3),
		(store_script_param,':lower_bound',4),
		(store_script_param,':upper_bound',5),
		(position_get_z,':pos_z',':pos'),
		(val_add,':pos_z',':displacement'),
		(try_begin),
			(eq,':clamp',true),
			(val_clamp,':pos_z',':lower_bound',':upper_bound'),
		(try_end),
		(position_set_x,':pos',':pos_z'),
		(copy_position,pos0,':pos'),
		]
	),
# script_modify_troop_wealth
('modify_troop_wealth',
	[
		(store_script_param,':troop_no',1),
		(troop_get_slot,':wealth',':troop_no',slot_troop_wealth),
		(store_troop_gold,':troop_gold',':troop_no'),
		(try_begin),
			(neq,':troop_gold',':wealth'),
			(assign,':wealth',':troop_gold'),
			(troop_set_slot,':troop_no',slot_troop_wealth,':wealth'),
		(try_end),
		]
	),
# script_get_upper_lower_bounds
# lower bound stored to reg0, upper bound stored to reg1
('get_upper_lower_bounds',
	[
		(store_script_param,':mean',1),
		(store_script_param,':percent_error',2),
		(store_div,':span',100,':percent_error'),
		(store_div,':delta',':mean',':span'),
		(store_sub,':lower_bound',':mean',':delta'),
		(store_add,':upper_bound',':mean',':delta'),
		(assign,reg0,':lower_bound'),
		(assign,reg1,':upper_bound'),
		]
	),
#####################################################################
# BoW: gets an item's value
# Param1: item ID
# Param2: item modifier
#####################################################################
("get_item_value_with_imod", [  # returns the sell price based on the item's money value and its imod
	(store_script_param, ":item", 1),
	(store_script_param, ":imod", 2),	
	(store_item_value, ":score", ":item"),
	(try_begin),
		(eq, ":imod", imod_lame),
		(val_mul, ":score", 30),
	(else_try),			
		(this_or_next|eq, ":imod", imod_tattered),
		(eq, ":imod", imod_cracked),
		(val_mul, ":score", 40),
	(else_try),			
		(this_or_next|eq, ":imod", imod_rusty),
		(eq, ":imod", imod_swaybacked),
		(val_mul, ":score", 50),
	(else_try),			
		(this_or_next|eq, ":imod", imod_ragged),
		(eq, ":imod", imod_bent),
		(val_mul, ":score", 60),
	(else_try),			
		(this_or_next|eq, ":imod", imod_chipped),
		(eq, ":imod", imod_battered),
		(val_mul, ":score", 65),
	(else_try),			
		(this_or_next|eq, ":imod", imod_poor),
		(eq, ":imod", imod_crude),
		(val_mul, ":score", 80),
	(else_try),
		(this_or_next|eq, ":imod", imod_old),
		(eq, ":imod", imod_stubborn),
		(val_mul, ":score", 90),
	(else_try),
		(eq, ":imod", imod_plain),
		(val_mul, ":score", 100),
	(else_try),			
		(eq, ":imod", imod_heavy),
		(val_mul, ":score", 135),
	(else_try),			
		(eq, ":imod", imod_large_bag),
		(val_mul, ":score", 190),
	(else_try),
		(eq, ":imod", imod_temperate),
		(val_mul, ":score", 140),
	(else_try),
		(eq, ":imod", imod_sturdy),
		(val_mul, ":score", 130),
	(else_try),
		(eq, ":imod", imod_thick),
		(val_mul, ":score", 160),
	(else_try),
		(eq, ":imod", imod_spirited),
		(val_mul, ":score", 240),
	(else_try),
		(eq, ":imod", imod_balanced),
		(val_mul, ":score", 170),
	(else_try),
		(eq, ":imod", imod_hardened),
		(val_mul, ":score", 180),
	(else_try),
		(eq, ":imod", imod_watered_steel),
		(val_mul, ":score", 290),
	(else_try),
		(eq, ":imod", imod_reinforced),
		(val_mul, ":score", 250),
	(try_end),
	
	(assign, reg0, ":score"),
]),

# script_get_current_weather
# Outputs rain type, strength, and fog visibility to reg0,reg1,reg2
('get_current_weather',
	[
		(store_script_param,':cur_month',1),
		(store_time_of_day,':cur_time'),
		(try_begin),
			(is_between,':cur_month',0,3),
			(assign,':rain_chance',30),
			(assign,':rain_type',1),
			(assign,':fog_chance',40),
		(else_try),
			(is_between,':cur_month',3,6),
			(assign,':rain_chance',40),
			(assign,':rain_type',0),
			(assign,':fog_chance',50),
		(else_try),(is_between,':cur_month',6,9),
			(assign,':rain_chance',10),
			(assign,':rain_type',0),
			(assign,':fog_chance',20),
		(else_try),(is_between,':cur_month',9,12),
			(assign,':rain_chance',20),
			(assign,':rain_type',1),
			(assign,':fog_chance',60),
		(try_end),
		(try_begin),
			(is_between,':cur_time',0,6),
			(val_add,':fog_chance',10),
		(else_try),
			(is_between,':cur_time',6,12),
			(val_sub,':rain_chance',10),
			(val_add,':fog_chance',10),
		(else_try),
			(is_between,':cur_time',12,18),
			(val_add,':rain_chance',15),
			(assign,':fog_chance',0),
		(else_try),
			(is_between,':cur_time',18,24),
			(assign,':fog_chance',0),
		(try_end),
		(store_random_in_range,':rain_roll',0,100),
		(store_random_in_range,':fog_roll',0,100),
		(try_begin),
			(lt,':rain_chance',':rain_roll'),
			(assign,reg0,':rain_type'),
			(store_random_in_range,reg1,0,100),
		(try_end),
		(try_begin),
			(lt,':fog_chance',':fog_roll'),
			(store_random_in_range,reg2,1,11),
			(val_mul,reg2,100),
		(try_end),
		]
	),

# Town walker scripts
  # script_init_town_walkers
  # Input: none
  # Output: none
  ("init_town_walkers",
    [(try_begin),
       (neg|is_currently_night),
       (store_random_in_range, ":num_walkers", 8, 9),
       (try_for_range, ":cur_walker", 0, 8),
         (try_begin),
           (lt, ":cur_walker", ":num_walkers"),
           (store_random_in_range, ":walker_troop", town_walkers_begin, town_walkers_end),
         (else_try),
           (assign, ":walker_troop", -1),
         (try_end),
         (try_begin),
           (eq, ":cur_walker", 0),
           (assign, reg0, ":walker_troop"),
         (else_try),
           (eq, ":cur_walker", 1),
           (assign, reg1, ":walker_troop"),
         (else_try),
           (eq, ":cur_walker", 2),
           (assign, reg2, ":walker_troop"),
         (else_try),
           (eq, ":cur_walker", 3),
           (assign, reg3, ":walker_troop"),
         (else_try),
           (eq, ":cur_walker", 4),
           (assign, reg4, ":walker_troop"),
         (else_try),
           (eq, ":cur_walker", 5),
           (assign, reg5, ":walker_troop"),
         (else_try),
           (eq, ":cur_walker", 6),
           (assign, reg6, ":walker_troop"),
         (else_try),
           (eq, ":cur_walker", 7),
           (assign, reg7, ":walker_troop"),
         (try_end),
       (try_end),
       (shuffle_range, 0, 8),
       (set_visitor, 32, reg0),
       (set_visitor, 33, reg1),
       (set_visitor, 34, reg2),
       (set_visitor, 35, reg3),
       (set_visitor, 36, reg4),
       (set_visitor, 37, reg5),
       (set_visitor, 38, reg6),
       (set_visitor, 39, reg7),
     (try_end),
  ]),
  
  # script_init_town_walker_agents
  # Input: none
  # Output: none
  ("init_town_walker_agents",
    [(try_for_agents, ":cur_agent"),
       (agent_get_troop_id, ":cur_troop", ":cur_agent"),
       (is_between, ":cur_troop", town_walkers_begin, town_walkers_end),
       (agent_get_position, pos1, ":cur_agent"),
       (try_for_range, ":i_e_p", 16, 40),#Entry points
         (entry_point_get_position, pos2, ":i_e_p"),
         (get_distance_between_positions, ":distance", pos1, pos2),
         (lt, ":distance", 200),
         (agent_set_slot, ":cur_agent", 0, ":i_e_p"),
       (try_end),
       (call_script, "script_set_town_walker_destination", ":cur_agent"),
     (try_end),
  ]),
  
  # script_tick_town_walkers
  # Input: none
  # Output: none
  ("tick_town_walkers",
    [(try_for_agents, ":cur_agent"),
       (agent_get_troop_id, ":cur_troop", ":cur_agent"),
       (is_between, ":cur_troop", town_walkers_begin, town_walkers_end),
       (agent_get_slot, ":target_entry_point", ":cur_agent", 0),
       (entry_point_get_position, pos1, ":target_entry_point"),
       (try_begin),
         (lt, ":target_entry_point", 32),
         (init_position, pos2),
         (position_set_y, pos2, 250),
         (position_transform_position_to_parent, pos1, pos1, pos2),
       (try_end),
       (agent_get_position, pos2, ":cur_agent"),
       (get_distance_between_positions, ":distance", pos1, pos2),
       (lt, ":distance", 400),
       (assign, ":random_no", 0),
       (try_begin),
         (lt, ":target_entry_point", 32),
         (store_random_in_range, ":random_no", 0, 100),
       (try_end),
       (lt, ":random_no", 20),
       (call_script, "script_set_town_walker_destination", ":cur_agent"),
     (try_end),
  ]),


  # script_set_town_walker_destination
  # Input: arg1 = agent_no
  # Output: none
  ("set_town_walker_destination",
    [(store_script_param_1, ":agent_no"),
     (assign, reg0, 16),
     (assign, reg1, 17),
     (assign, reg2, 18),
     (assign, reg3, 32),
     (assign, reg4, 33),
     (assign, reg5, 34),
     (assign, reg6, 35),
     (assign, reg7, 36),
     (assign, reg8, 37),
     (assign, reg9, 38),
     (assign, reg10, 39),
     (try_for_agents, ":cur_agent"),
       (agent_get_troop_id, ":cur_troop", ":cur_agent"),
       (is_between, ":cur_troop", town_walkers_begin, town_walkers_end),
       (agent_get_slot, ":target_entry_point", ":cur_agent", 0),
       (try_begin),
         (eq, ":target_entry_point", 16),
         (assign, reg0, 0),
       (else_try),
         (eq, ":target_entry_point", 17),
         (assign, reg1, 0),
       (else_try),
         (eq, ":target_entry_point", 18),
         (assign, reg2, 0),
       (else_try),
         (eq, ":target_entry_point", 32),
         (assign, reg3, 0),
       (else_try),
         (eq, ":target_entry_point", 33),
         (assign, reg4, 0),
       (else_try),
         (eq, ":target_entry_point", 34),
         (assign, reg5, 0),
       (else_try),
         (eq, ":target_entry_point", 35),
         (assign, reg6, 0),
       (else_try),
         (eq, ":target_entry_point", 36),
         (assign, reg7, 0),
       (else_try),
         (eq, ":target_entry_point", 37),
         (assign, reg8, 0),
       (else_try),
         (eq, ":target_entry_point", 38),
         (assign, reg9, 0),
       (else_try),
         (eq, ":target_entry_point", 39),
         (assign, reg10, 0),
       (try_end),
     (try_end),
     (assign, ":try_limit", 100),
     (assign, ":target_entry_point", 0),
     (try_for_range, ":unused", 0, ":try_limit"),
       (shuffle_range, 0, 11),
       (gt, reg0, 0),
       (assign, ":target_entry_point", reg0),
       (assign, ":try_limit", 0),
     (try_end),
     (try_begin),
       (gt, ":target_entry_point", 0),
       (agent_set_slot, ":agent_no", 0, ":target_entry_point"),
       (entry_point_get_position, pos1, ":target_entry_point"),
       (try_begin),
         (lt, ":target_entry_point", 32),
         (init_position, pos2),
         (position_set_y, pos2, 250),
         (position_transform_position_to_parent, pos1, pos1, pos2),
       (try_end),
       (agent_set_scripted_destination, ":agent_no", pos1, 0),
       (agent_set_speed_limit, ":agent_no", 5),
     (try_end),
  ]),

#####################################################################
# BoW: sorts a troops inventory by price
# Param1: source troop
#####################################################################
("sort_inventory", [
	(store_script_param_1, ":source_troop"),
	(troop_get_inventory_capacity, ":inv_cap", ":source_troop"),
	(assign, ":num_items", 0),
	# record the item IDs
	(try_for_range, ":i_slot", 0, ":inv_cap"),
		(troop_get_inventory_slot, ":item_id", ":source_troop", ":i_slot"),
		(ge, ":item_id", 0),
		(troop_set_slot, "trp_temp_array_a", ":num_items", ":item_id"),
		(troop_get_inventory_slot_modifier, ":item_imod", ":source_troop", ":i_slot"),
		(troop_set_slot, "trp_temp_array_b", ":num_items", ":item_imod"),
		(troop_inventory_slot_get_item_amount, ":item_amount", ":source_troop", ":i_slot"),
		(troop_set_slot, "trp_temp_array_c", ":num_items", ":item_amount"),
		(val_add, ":num_items", 1),
	(try_end),
	# bubble-sort by cost
	(try_for_range, ":i_slot", 1, ":num_items"),
		(try_for_range_backwards, ":j_slot", ":i_slot",":num_items"),
			(try_begin),
				(store_sub, ":prev_slot", ":j_slot", 1),
				(troop_get_slot, ":item_j", "trp_temp_array_a", ":j_slot"),
				(troop_get_slot, ":item_prev", "trp_temp_array_a", ":prev_slot"),
				(troop_get_slot, ":item_imod_j", "trp_temp_array_b", ":j_slot"),
				(troop_get_slot, ":item_imod_prev", "trp_temp_array_b", ":prev_slot"),
				(troop_get_slot, ":item_amt_j", "trp_temp_array_c", ":j_slot"),
				(troop_get_slot, ":item_amt_prev", "trp_temp_array_c", ":prev_slot"),
				(call_script, "script_get_item_value_with_imod", ":item_j", ":item_imod_j"),
				(assign, ":item_cost_j", reg0),
				(call_script, "script_get_item_value_with_imod", ":item_prev", ":item_imod_prev"),
				(assign, ":item_cost_prev", reg0),
				(lt, ":item_cost_prev", ":item_cost_j"),
				# out of order; do the swap
				(troop_set_slot, "trp_temp_array_a", ":j_slot", ":item_prev", ),
				(troop_set_slot, "trp_temp_array_a", ":prev_slot", ":item_j"),
				(troop_set_slot, "trp_temp_array_b", ":j_slot", ":item_imod_prev", ),
				(troop_set_slot, "trp_temp_array_b", ":prev_slot", ":item_imod_j"),
				(troop_set_slot, "trp_temp_array_c", ":j_slot", ":item_amt_prev", ),
				(troop_set_slot, "trp_temp_array_c", ":prev_slot", ":item_amt_j"),
			(try_end),
		(try_end),
	(try_end),
	# remove items
	(troop_clear_inventory, ":source_troop"),
	(try_for_range, ":i_slot", 0, 10),
		(troop_set_inventory_slot, ":source_troop", ":i_slot", -1),
	(end_try),	
	# replace them on the troop, most expensive first		
	(try_for_range, ":i_slot", 0, ":num_items"),				
		(troop_get_slot, ":item_id", "trp_temp_array_a", ":i_slot"),
		(troop_get_slot, ":item_imod", "trp_temp_array_b", ":i_slot"),
		(troop_get_slot, ":item_amount", "trp_temp_array_c", ":i_slot"),
		(troop_add_item, ":source_troop", ":item_id", ":item_imod"),
		(try_begin),
			(is_between, ":item_id", morale_boosters_begin, morale_boosters_end),
			(store_add, ":inv_slot", ":i_slot", 10),
			(troop_inventory_slot_set_item_amount, ":source_troop", ":inv_slot", ":item_amount"),
		(try_end),	
	(try_end),
]),
# script_item_get_random_imod
('item_get_random_imod',
	[
		(store_script_param,':item_type',1),
		(assign,':result',imod_plain),
		(try_begin),
			(eq,':item_type',itp_type_horse),
			(call_script,'script_clear_temp_array','trp_temp_array_a',10),
			(assign,':temp_array_index',0),
			(troop_set_slot,'trp_temp_array_a',':temp_array_index',imod_plain),
			(val_add,':temp_array_index',1),
			(troop_set_slot,'trp_temp_array_a',':temp_array_index',imod_heavy),
			(val_add,':temp_array_index',1),
			(try_for_range,':imod',imod_lame,imod_large_bag),
				(troop_set_slot,'trp_temp_array_a',':temp_array_index',':imod'),
				(val_add,':temp_array_index',1),
			(try_end),
			(store_random_in_range,':temp_index',0,':temp_array_index'),
			(troop_get_slot,':result','trp_temp_array_a',':temp_index'),
		(try_end),
		(assign,reg0,':result'),
		]
	),
      # script player has troops
("player_has_troops",
[
	(try_begin),
		(call_script,"script_list_party_troops",'p_main_party'),
		(str_store_party_name,3,reg5),
		(display_message,"str_party_contains"),
		(try_for_range,reg6,0,reg9),
			(troop_get_slot,reg7,"trp_end_troops",reg6),
			(str_store_troop_name,3,reg7),
			(display_message,"str_string3"),
		(try_end),
	(try_end)
]),
      
      # script get location
      ("get_location",
        [
          (store_encountered_party,reg1),
          (store_current_scene,reg2),
          (try_begin),
            (eq,reg1,south_kyoto),
            (scene_set_slot,reg2,1,1),
          (else_try),
            (eq,reg1,yodo),
            (scene_set_slot,reg2,1,2),
          (else_try),
            (eq,reg1,hikone),
            (scene_set_slot,reg2,1,3),
          (else_try),
            (eq,reg1,oya),
            (scene_set_slot,reg2,1,4),
          (else_try),
            (eq,reg1,oe),
            (scene_set_slot,reg2,1,5),
          (else_try),
            (eq,reg1,imazu),
            (scene_set_slot,reg2,1,6),
          (else_try),
            (eq,reg1,haga),
            (scene_set_slot,reg2,1,7),
          (else_try),
            (eq,reg1,iga),
            (scene_set_slot,reg2,1,8),
          (try_end)
      ]),
      
      # script player has faction troops
      # inputs: :input_party (usually the main party), :input_faction (the target faction, hosokawa or yamana)
      
("player_has_faction_troops",
	[
		(store_script_param_1,':input_party'),
		(store_script_param_2,':input_faction'),
		(call_script,"script_list_party_troops",':input_party'),
		(assign,':num_enemy_troops',0),
		(try_for_range,':temp_array_index',0,'trp_last_troop'),
			(troop_get_slot,':troop_no','trp_last_troop',':temp_array_index'),
			(store_troop_faction,':troop_faction',':troop_no'),
			(eq,':troop_faction',':input_faction'),
			(val_add,':num_enemy_troops',1),
		(try_end),
		(assign,"$return",0),
		(try_begin),
			(gt,':num_enemy_troops',0),
			(assign,"$return",1),
		(try_end),
		]
	),
# script_get_random_object_in_range_exclusive
('get_random_object_in_range_exclusive',
	[
		(store_script_param,':lower_bound',1),
		(store_script_param,':upper_bound',2),
		(store_script_param,':exclude',3),
		(store_random_in_range,reg0,':lower_bound',':upper_bound'),
		(try_begin),
			(eq,reg0,':exclude'),
			(call_script,'script_get_random_object_in_range_exclusive',':lower_bound',':upper_bound',':exclude'),
		(try_end),
		]
	),
# script_cf_get_position_between_positions
('cf_get_position_between_positions',
	[
		(store_script_param,':pos1_x',1),
		(store_script_param,':pos1_y',2),
		(store_script_param,':pos2_x',3),
		(store_script_param,':pos2_y',4),
		(init_position,pos20),
		(init_position,pos21),
		(position_set_x,pos20,':pos1_x'),
		(position_set_y,pos20,':pos1_y'),
		(position_set_x,pos21,':pos2_x'),
		(position_set_y,pos21,':pos2_y'),
		(get_distance_between_positions,':dist',pos20,pos21),
		(map_get_land_position_around_position,pos0,pos20,':dist'),
		(get_distance_between_positions,':dist2',pos0,pos21),
		(try_begin),
			(gt,':dist2',':dist'),
			(call_script,'script_cf_get_position_between_positions',':pos1_x',':pos1_y',':pos2_x',':pos2_y'),
		(try_end),
		]
	),
# script_start_quest
('start_quest',
	[
		(store_script_param,':quest_no',1),
		(start_quest,':quest_no'),
		(quest_get_slot, ":quest_giver_troop", ":quest_no", slot_quest_giver),
		(str_store_troop_name, s59, ":quest_giver_troop"),
		(add_quest_note_from_sreg,':quest_no',5,'@You have been given a quest by {s59}.',1),
		]
	),
  #script_conclude_quest
  # INPUT: arg1 = quest_no
  # OUTPUT: none
  ("conclude_quest",
    [(store_script_param, ":quest_no", 1),
     (conclude_quest, ":quest_no"),
     (quest_get_slot, ":quest_giver_troop", ":quest_no", slot_quest_giver),
     (str_store_troop_name, s59, ":quest_giver_troop"),
     (add_quest_note_from_sreg, ":quest_no", 5, "@This quest has been concluded. Talk to {s59} to finish it.",1),
     ]),

  #script_succeed_quest
  # INPUT: arg1 = quest_no
  # OUTPUT: none
  ("succeed_quest",
    [(store_script_param, ":quest_no", 1),
     (succeed_quest, ":quest_no"),
     (quest_get_slot, ":quest_giver_troop", ":quest_no", slot_quest_giver),
     (str_store_troop_name, s59, ":quest_giver_troop"),
     (add_quest_note_from_sreg, ":quest_no", 5, "@This quest has been successfully completed. Talk to {s59} to claim your reward.",1),
     ]),

  #script_fail_quest
  # INPUT: arg1 = quest_no
  # OUTPUT: none
  ("fail_quest",
    [(store_script_param, ":quest_no", 1),
     (fail_quest, ":quest_no"),
     (quest_get_slot, ":quest_giver_troop", ":quest_no", slot_quest_giver),
     (str_store_troop_name, s59, ":quest_giver_troop"),
     (add_quest_note_from_sreg, ":quest_no", 5, "@This quest has failed. Talk to {s59} to explain the situation.",1),
     ]),

  #script_end_quest
  # INPUT: arg1 = quest_no
  # OUTPUT: none
  ("end_quest",
    [(store_script_param, ":quest_no", 1),
     (str_clear, s1),
     (add_quest_note_from_sreg, ":quest_no", 1, s1, 0),
     (add_quest_note_from_sreg, ":quest_no", 2, s1, 0),
     (add_quest_note_from_sreg, ":quest_no", 3, s1, 0),
     (add_quest_note_from_sreg, ":quest_no", 4, s1, 0),
     (add_quest_note_from_sreg, ":quest_no", 5, s1, 0),
     (complete_quest, ":quest_no"),
	 (cancel_quest,':quest_no'),
	 (call_script,"script_reset_quest_registers",':quest_no'),
     ]),
# script_cf_get_partner_quest
('cf_get_partner_quest',
	[
		(store_script_param,':troop',1),
		(troop_get_slot,reg0,':troop',slot_troop_quest),
		(gt,reg0,0),
		]
	),
# script_get_active_quest
('cf_get_active_quest',
	[
		(assign,reg0,null),
		(try_begin),
			(check_quest_active,'qst_class_bushi'),
			(try_for_range,':quest',bushi_random_quests_begin,bushi_random_quests_end),
				(check_quest_active,':quest'),
				(assign,reg0,':quest'),
			(try_end),
		(else_try),
			(check_quest_active,'qst_class_kuge'),
			(try_for_range,':quest',kuge_random_quests_begin,kuge_random_quests_end),
				(check_quest_active,':quest'),
				(assign,reg0,':quest'),
			(try_end),
		(else_try),
			(check_quest_active,'qst_class_ronin_investigator'),
			(try_for_range,':quest',ronin_random_quests_begin,ronin_random_quests_end),
				(check_quest_active,':quest'),
				(assign,reg0,':quest'),
			(try_end),
		(else_try),
			(check_quest_active,'qst_class_merchant'),
			(try_for_range,':quest',merchant_random_quests_begin,merchant_random_quests_end),
				(check_quest_active,':quest'),
				(assign,reg0,':quest'),
			(try_end),
		(try_end),
		(neq,reg0,null)
		],
	),
# assign the quest
('get_class_quest',
	[
		(try_begin),
			(eq,'$storyline_quest_flag',1),
			(try_begin),
				(check_quest_active,'qst_class_bushi'),
				(call_script,'script_array_poke','$bushi_storyline_quest_array','$ptr_bushi_storyline_quest_array'),
				(val_add,'$ptr_bushi_storyline_quest_array',1),
				(assign,':quest','$return'),
			(else_try),
				(check_quest_active,'qst_class_kuge'),
				(call_script,'script_array_poke','$kuge_storyline_quest_array','$ptr_kuge_storyline_quest_array'),
				(val_add,'$ptr_kuge_storyline_quest_array',1),
				(assign,':quest','$return'),
			(else_try),
				(check_quest_active,'qst_class_ronin'),
				(call_script,'script_array_poke','$ronin_storyline_quest_array','$ptr_ronin_storyline_quest_array'),
				(val_add,'$ptr_ronin_storyline_quest_array',1),
				(assign,':quest','$return'),
			(else_try),
				(check_quest_active,'qst_class_merchant'),
				(call_script,'script_array_poke','$merchant_storyline_quest_array','$ptr_merchant_storyline_quest_array'),
				(val_add,'$ptr_merchant_storyline_quest_array',1),
				(assign,':quest','$return'),
			(try_end),
		(else_try),
			(store_random_in_range,reg41,0,10),
			(try_begin),
				(lt,reg41,9),
				(try_begin),
					(check_quest_active,'qst_class_bushi'),
					(store_random_in_range,':quest',bushi_random_quests_begin,bushi_random_quests_end),
				(else_try),
					(check_quest_active,'qst_class_kuge'),
					(store_random_in_range,':quest',kuge_random_quests_begin,kuge_random_quests_end),
				(else_try),
					(check_quest_active,'qst_class_ronin_investigator'),
					(store_random_in_range,':quest',ronin_random_quests_begin,ronin_random_quests_end),
				(else_try),
					(check_quest_active,'qst_class_merchant'),
					(store_random_in_range,':quest',merchant_random_quests_begin,merchant_random_quests_end),
					# (assign,':quest','qst_merchant_establish_trading_post'),
				(try_end),
			(else_try),
				(assign,':quest',null),
			(try_end),
		(try_end),
		(assign,'$storyline_quest_flag',0),
		(assign,reg0,':quest'),
		]
	),
#script_shugo_quest_accept	  
('shugo_quest_accept',
	[
		(store_script_param,':quest_no',1),
		(store_script_param,':quest_giver',2),
		(try_begin),
			(eq,':quest_no','qst_storyline_bushi_rebellion'),
			(assign,'$num_rebel_parties',0),
			(store_num_parties_destroyed,'$num_rebel_parties_destroyed','pt_ikko_ikki_rebels'),
			#(call_script,'script_select_random_faction_city','$shugo_faction'),
			(assign,'$return',hyogo),
			(party_get_slot,':prefecture_towns','$return',slot_town_dest_array),
			(party_get_slot,':array_length',':prefecture_towns',array_value_length),
			(try_for_range,':unused',0,':array_length'),
				(call_script,'script_array_cycle',':prefecture_towns'),
				(set_spawn_radius,0),
				(spawn_around_party,'$return','pt_ikko_ikki_rebels'),
				(party_set_ai_behavior,reg0,ai_bhvr_patrol_party),
				(party_set_ai_object,reg0,'$return'),
				(party_set_slot,reg0,slot_spawn_att_to_player,att_hostile),
				(val_add,'$num_rebel_parties',1),
			(try_end),
		(else_try),
			(eq,':quest_no','qst_storyline_bushi_enemy_patrols'),
			(call_script,'script_get_shugo_faction'),
			(assign,':shugo_faction',reg0),
			# (assign,':shugo_enemy_faction',reg1),
			(try_begin),
				(eq,':shugo_faction','fac_hosokawa'),
				(assign,'$target_enemy_patrol','pt_yamana_patrol'),
			(else_try),
				(eq,':shugo_faction','fac_yamana'),
				(assign,'$target_enemy_patrol','pt_hosokawa_patrol'),
			(try_end),
			(store_num_parties_destroyed_by_player,'$num_enemy_patrols_destroyed','$target_enemy_patrol'),
		(else_try),
			(eq,':quest_no','qst_storyline_bushi_establish_outpost'),
			(call_script,'script_spawn_builder','$g_encountered_party'),
		(else_try), # ronin quests
			(eq,':quest_no','qst_ronin_defeat_bandit_parties'),
			(store_random_in_range,reg1,2,6),
			(quest_set_slot,'qst_ronin_defeat_bandit_parties',slot_quest_pt_count,reg1),
			(quest_set_slot,'qst_ronin_defeat_bandit_parties',slot_quest_pt_defeated,0),
			(setup_quest_text,'qst_ronin_defeat_bandit_parties'),
		(else_try),
			(eq,':quest_no','qst_ronin_apprehend_bandits'),
			(setup_quest_text,'qst_ronin_apprehend_bandits'),
		(else_try),
			(eq,':quest_no','qst_ronin_investigate_bandit_activity'),
			(quest_set_slot,'qst_ronin_investigate_bandit_activity',slot_quest_flags,0),
			(quest_get_slot,':target_city','qst_ronin_investigate_bandit_activity',slot_quest_party_1),
			(str_store_party_name,10,':target_city'), # bandit special party spawned here and disabled
			(setup_quest_text,'qst_ronin_investigate_bandit_activity'),
		(else_try),
			(eq,':quest_no',"qst_bushi_suppress_rebels"),
			(set_spawn_radius,3),
			(quest_get_slot,':target_city',':quest_no',slot_quest_target_party),
			(spawn_around_party,':target_city',"pt_ikko_ikki_rabble"),
			(assign,':target_party',reg0),
			(party_set_ai_behavior,':target_party',ai_bhvr_patrol_party),
			(party_set_ai_object,':target_party',':target_city'),
			(quest_set_slot,':quest_no',slot_quest_target_party_2,':target_party'),
			(assign,"$shugo_rebel_flag",1),
			(str_store_party_name,s10,':target_city'),
			(setup_quest_text,"qst_bushi_suppress_rebels"),
		(else_try),
			(eq,":quest_no","qst_bushi_defeat_enemy_local_garrisons"),
			(store_num_parties_destroyed_by_player,"$local_patrols_defeated","pt_local_patrol"),
			(setup_quest_text,"qst_bushi_defeat_enemy_local_garrisons"),
		(else_try),
			(this_or_next|eq,":quest_no","qst_kuge_war_materials"),
			(eq,":quest_no","qst_bushi_war_materials"),
			(quest_get_slot,reg2,':quest_no',slot_quest_item_1),
			(quest_get_slot,reg3,':quest_no',slot_quest_target_troop),
			(troop_add_item,"trp_player",reg2,0),
			(troop_get_slot,reg4,reg3,slot_troop_city),
			(str_store_item_name,s10,reg2),
			(str_store_troop_name,s11,reg3),
			(str_store_party_name,s12,reg4),
			(assign,':quest_no_time',10),
			(assign,reg10,":quest_no_time"),
			(setup_quest_text,"qst_kuge_war_materials"),
			(setup_quest_text,"qst_bushi_war_materials"),
		(else_try),
			(eq,":quest_no","qst_bushi_reconnoiter_enemy_army"),
			(troop_get_slot,':retainer_faction','trp_player',slot_player_faction),
			(faction_get_slot,':enemy_faction',':retainer_faction',slot_faction_enemy_faction),
			(call_script,'script_clear_temp_array','trp_temp_array_a',100),
			(assign,':temp_array_index',0),
			(try_for_parties,':party_no'),
				(call_script,'script_cf_party_is_of_template',':party_no','pt_army'),
				(store_faction_of_party,':party_fac',':party_no'),
				(eq,':party_fac',':enemy_faction'),
				(troop_set_slot,'trp_temp_array_a',':temp_array_index',':party_no'),
				(val_add,':temp_array_index',1),
			(try_end),
			(store_random_in_range,':slot_no',0,':temp_array_index'),
			(troop_get_slot,':target_party','trp_temp_array_a',':slot_no'),
			(quest_set_slot,'qst_bushi_reconnoiter_enemy_army',slot_quest_target_party,':target_party'),
			(party_get_slot,':army_base',':target_party',slot_army_base),
			(store_skill_level,':spotting_skill',skl_spotting,'trp_player'),
			(store_random_in_range,"$g_scout_range",0,5),
			(val_add,'$g_scout_range',':spotting_skill'),
			(val_add,"$g_scout_range",2),
			(str_store_party_name,s10,':army_base'),
			(setup_quest_text,"qst_bushi_reconnoiter_enemy_army"),
		(else_try),
			(eq,":quest_no","qst_kuge_emissary"),
			(str_store_troop_name,s10,':quest_giver'),
			(setup_quest_text,"qst_kuge_emissary"),
		(else_try),
			(eq,":quest_no","qst_kuge_entertain_visiting_kuge"),
			(quest_get_slot,':quest_item',':quest_no',slot_quest_item_1),
			(str_store_troop_name,s10,':quest_giver'),
			(str_store_item_name,s11,':quest_item'),
			(setup_quest_text,"qst_kuge_entertain_visiting_kuge"),
		(try_end),
		(quest_set_slot,':quest_no',slot_quest_giver,':quest_giver'),
		(str_store_troop_name,s10,':quest_giver'),
		(setup_quest_giver,':quest_no',s12),
		(troop_set_slot,':quest_giver',slot_troop_quest,':quest_no'),
		(troop_set_slot,':quest_giver',slot_troop_quest_active,1),
		(call_script,'script_start_quest',":quest_no"),
		]
	),
# script_kokujin_quest_accept
('kokujin_quest_accept',
	[
		(store_script_param,':quest_no',1),
		(try_begin),
			(eq,':quest_no','qst_kokujin_defeat_bandits'),
			(set_spawn_radius,4),
			(spawn_around_party,'$g_encountered_party',"pt_bandit_raiders_b"),
			(party_set_ai_behavior,reg0,ai_bhvr_patrol_party),
			(party_set_ai_object,reg0,'$g_encountered_party'),
			(quest_set_slot,':quest_no',slot_quest_target_party,reg0),
			(str_store_party_name,s10,'$g_encountered_party'),
			(quest_get_slot,':quest_giver',':quest_no',slot_quest_giver),
			(str_store_troop_name,s11,':quest_giver'),
			(setup_quest_giver,':quest_no',s11),
			(setup_quest_text,':quest_no'),
		(else_try),
			(eq,':quest_no','qst_kokujin_needs_goods'),
			(quest_get_slot,':quest_giver',':quest_no',slot_quest_giver),
			(quest_get_slot,':quest_item',':quest_no',slot_quest_item_1),
			(quest_get_slot,reg3,':quest_no',slot_quest_item_1_cnt),
			(str_store_party_name,s10,'$g_encountered_party'),
			(str_store_item_name,s11,':quest_item'),
			(str_store_troop_name,s12,':quest_giver'),
			(setup_quest_giver,':quest_no',s12),
			(setup_quest_text,':quest_no'),
		(else_try),
			(eq,':quest_no','qst_kokujin_deliver_msg'),
			(quest_get_slot,':quest_giver',':quest_no',slot_quest_giver),
			(quest_get_slot,':target_party',':quest_no',slot_quest_target_party),
			(str_store_party_name,s10,'$g_encountered_party'),
			(str_store_party_name,s11,':target_party'),
			(str_store_troop_name,s12,':quest_giver'),
			(setup_quest_giver,':quest_no',s12),
			(setup_quest_text,':quest_no'),
		(try_end),
		(troop_set_slot,':quest_giver',slot_troop_quest,':quest_no'),
        (troop_set_slot,':quest_giver',slot_troop_quest_active,1),
        ]
	),
# script_merchant_quest_accept
('merchant_quest_accept',
	[
		(store_script_param,':quest_no',1),
		#(display_message,'@Sanity check merchant quest',debug_text),
		(store_script_param,':quest_giver',2),
		(try_begin),
			(eq,':quest_no','qst_merchant_establish_trading_post'),
			(call_script,'script_get_random_object_in_range_exclusive',hyogo,villages_end,null),
			(assign,':target_city',reg0),
			(party_get_slot,':target_troop',':target_city',slot_town_kokujin),
			(call_script,'script_object_modify_slot',obj_quest,'qst_merchant_establish_trading_post',slot_quest_target_party,op_asn,':target_city'),
			(call_script,'script_object_modify_slot',obj_quest,'qst_merchant_establish_trading_post',slot_quest_target_troop,op_asn,':target_troop'),
			(str_store_party_name,s10,':target_city'),
			(str_store_troop_name,s11,':target_troop'),
			(str_store_troop_name,s12,':quest_giver'),
			(assign,'$g_num_negotiation_attempts',0),
			(setup_quest_text,'qst_merchant_establish_trading_post'),
			(setup_quest_giver,'qst_merchant_establish_trading_post',s12),
		(else_try),
			(eq,':quest_no','qst_merchant_patrol_trade_route'),
			(store_random_in_range,':current_day',5,11),
			(call_script,'script_get_random_object_in_range_exclusive',hyogo,cities_end,'$g_encountered_party'),
			(assign,':target_city_1',reg0),
			(call_script,'script_get_trade_dest',':target_city_1'),
			(assign,':target_city_2',reg0),
			(party_get_position,pos1,':target_city_1'),
			(party_get_position,pos2,':target_city_2'),
			(position_get_x,reg10,pos1),
			(position_get_y,reg11,pos1),
			(position_get_x,reg12,pos2),
			(position_get_y,reg13,pos2),
			(call_script,'script_cf_get_position_between_positions',reg10,reg11,reg12,reg13),
			(position_get_x,reg14,pos0),
			(position_get_y,reg15,pos0),
			(display_message,'@Pos1: ({reg10},{reg11}); Pos2: ({reg12},{reg13}); Pos0: ({reg14},{reg15})'),
			(call_script,'script_spawn_spawn_point',':target_city_1',reg14,reg15),
			(assign,':spawn_point',reg0),
			(set_spawn_radius,0),
			(spawn_around_party,':spawn_point','pt_bandit_raiders_b'),
			(party_add_members,reg0,'trp_bandit_leader',1),
			(party_set_slot,reg0,slot_spawn_att_to_player,att_hostile),
			(quest_set_slot,':quest_no',slot_quest_target_party,reg0),
			(quest_set_slot,':quest_no',slot_quest_party_1,':target_city_1'),
			(quest_set_slot,':quest_no',slot_quest_party_2,':target_city_2'),
			(quest_set_slot,':quest_no',slot_quest_party_3,':spawn_point'),
			(quest_set_slot,':quest_no',slot_quest_time_to_completion,':current_day'),
			(quest_set_slot,':quest_no',slot_quest_timed,true),
			(str_store_troop_name,13,':quest_giver'),
			(setup_quest_giver,'qst_merchant_deliver_shipment',s13),
			(setup_quest_text,'qst_merchant_deliver_shipment'),
		(else_try),
			(eq,':quest_no','qst_merchant_defend_trade_route'),
		(else_try),
			(eq,':quest_no','qst_merchant_deliver_shipment'),
			(store_random_in_range,':item_type_to_deliver',0,6),
			(try_begin),
				# (is_between,':item_type_to_deliver',3,6),
				(is_between,':item_type_to_deliver',0,6),
				(store_random_in_range,':item_no',trade_goods_begin,trade_goods_end),
				(call_script,'script_get_random_object_in_range_exclusive',hyogo,villages_end,'$g_encountered_party'),
				(assign,':quest_target_town',reg0),
				(party_get_slot,':quest_target_troop',':quest_target_town',slot_town_merchant),
				(store_free_inventory_capacity,':inv_cap','trp_player'),
				(store_random_in_range,':item_qty',1,':inv_cap'),
				(store_random_in_range,':time_to_completion',4,8),
				(troop_add_items,'trp_player',':item_no',':item_qty'),
				(quest_set_slot,':quest_no',slot_quest_item_1,':item_no'),
				(quest_set_slot,':quest_no',slot_quest_item_1_cnt,':item_qty'),
				(quest_set_slot,':quest_no',slot_quest_target_troop,':quest_target_troop'),
				(quest_set_slot,':quest_no',slot_quest_target_party,':quest_target_town'),
				(quest_set_slot,':quest_no',slot_quest_timed,true),
				(quest_set_slot,':quest_no',slot_quest_time_to_completion,':time_to_completion'),
				(assign,reg10,':time_to_completion'),
				(str_store_item_name,10,':item_no'),
				(str_store_troop_name,11,':quest_target_troop'),
				(str_store_party_name,12,':quest_target_town'),
				(str_store_troop_name,13,':quest_giver'),
				(setup_quest_giver,'qst_merchant_deliver_shipment',s13),
				(setup_quest_text,'qst_merchant_deliver_shipment'),
			(else_try),
				(is_between,':item_type_to_deliver',1,3),
				(try_begin),
					(check_quest_active,'qst_faction_enza'),
					(quest_get_slot,':item_no','qst_faction_enza',slot_quest_za_faction_item),
				(else_try),
					(check_quest_active,'qst_faction_ginza'),
					(quest_get_slot,':item_no','qst_faction_ginza',slot_quest_za_faction_item),
				(else_try),
					(check_quest_active,'qst_faction_andaza'),
					(quest_get_slot,':item_no','qst_faction_andaza',slot_quest_za_faction_item),
				(try_end),
				(call_script,'script_get_random_object_in_range_exclusive',hyogo,villages_end,'$g_encountered_party'),
				(assign,':quest_target_town',reg0),
				(party_get_slot,':quest_target_troop',':quest_target_town',slot_town_merchant),
				(store_free_inventory_capacity,':inv_cap','trp_player'),
				(store_random_in_range,':item_qty',1,':inv_cap'),
				(store_random_in_range,':time_to_completion',3,6),
				(troop_add_items,'trp_player',':item_no',':item_qty'),
				(quest_set_slot,':quest_no',slot_quest_item_1,':item_no'),
				(quest_set_slot,':quest_no',slot_quest_item_1_cnt,':item_qty'),
				(quest_set_slot,':quest_no',slot_quest_target_troop,':quest_target_troop'),
				(quest_set_slot,':quest_no',slot_quest_target_party,':quest_target_town'),
				(quest_set_slot,':quest_no',slot_quest_timed,true),
				(quest_set_slot,':quest_no',slot_quest_time_to_completion,':time_to_completion'),
				(assign,reg10,':time_to_completion'),
				(str_store_item_name,10,':item_no'),
				(str_store_troop_name,11,':quest_target_troop'),
				(str_store_party_name,12,':quest_target_town'),
				(str_store_troop_name,13,':quest_giver'),
				(setup_quest_giver,'qst_merchant_deliver_shipment',s13),
				(setup_quest_text,'qst_merchant_deliver_shipment'),
			(else_try),
				(is_between,':item_type_to_deliver',0,1),
				(store_random_in_range,':currency_type',0,3),
				(try_begin),
					(eq,':currency_type',0),
					(assign,':item_no','itm_string_of_coins'),
				(try_begin),
					(eq,':currency_type',1),
					(assign,':item_no','itm_koban'),
				(try_begin),
					(eq,':currency_type',2),
					(assign,':item_no','itm_stack_of_koban'),
				(try_end),
				(call_script,'script_get_random_object_in_range_exclusive',hyogo,villages_end,'$g_encountered_party'),
				(assign,':quest_target_town',reg0),
				(party_get_slot,':quest_target_troop',':quest_target_town',slot_town_merchant),
				(store_free_inventory_capacity,':inv_cap','trp_player'),
				(store_random_in_range,':item_qty',1,':inv_cap'),
				(store_random_in_range,':time_to_completion',2,6),
				(troop_add_items,'trp_player',':item_no',':item_qty'),
				(quest_set_slot,':quest_no',slot_quest_item_1,':item_no'),
				(quest_set_slot,':quest_no',slot_quest_item_1_cnt,':item_qty'),
				(quest_set_slot,':quest_no',slot_quest_target_troop,':quest_target_troop'),
				(quest_set_slot,':quest_no',slot_quest_target_party,':quest_target_town'),
				(quest_set_slot,':quest_no',slot_quest_timed,true),
				(quest_set_slot,':quest_no',slot_quest_time_to_completion,':time_to_completion'),
				(assign,reg10,':time_to_completion'),
				(str_store_item_name,10,':item_no'),
				(str_store_troop_name,11,':quest_target_troop'),
				(str_store_party_name,12,':quest_target_town'),
				(str_store_troop_name,13,':quest_giver'),
				(setup_quest_giver,'qst_merchant_deliver_shipment',s13),
				(setup_quest_text,'qst_merchant_deliver_shipment'),
			(try_end),
		(else_try),
			(eq,':quest_no','qst_merchant_escort_duty'),
		(else_try),
			(eq,':quest_no','qst_merchant_negotiate_trade_contract'),
			(call_script,'script_get_random_object_in_range_exclusive',hyogo,towns_end,'$g_encountered_party'),
			(assign,':target_city',reg0),
			(party_get_slot,':target_troop',':target_city',slot_town_kokujin),
			(call_script,'script_object_modify_slot',obj_quest,'qst_merchant_negotiate_trade_contract',slot_quest_target_party,op_asn,':target_city'),
			(call_script,'script_object_modify_slot',obj_quest,'qst_merchant_negotiate_trade_contract',slot_quest_target_troop,op_asn,':target_troop'),
			(assign,'$g_num_negotiation_attempts',0),
			(str_store_party_name,s11,':target_city'),
			(str_store_troop_name,s10,':target_troop'),
			(str_store_troop_name,s12,':quest_giver'),
			(setup_quest_text,'qst_merchant_negotiate_trade_contract'),
			(setup_quest_giver,'qst_merchant_negotiate_trade_contract',s12),
		(else_try),
			(eq,':quest_no','qst_merchant_enforcer'),
		(try_end),
		# (quest_set_slot,':quest_no',slot_quest_giver,':quest_giver'),
		# (troop_set_slot,':quest_giver',slot_troop_quest,':quest_no'),
        # (troop_set_slot,':quest_giver',slot_troop_quest_active,1),
        # (call_script,'script_start_quest',":quest_no"),
		]
	),
# script_merchant_quest_reward
('merchant_quest_reward',
	[
		(store_script_param,':quest_no',1),
		(try_begin),
			(eq,':quest_no','qst_merchant_patrol_trade_route'),
			(assign,':reward_mul',1),
			(try_begin),
				(main_party_has_troop,'trp_bandit_leader'),
				(assign,':reward_mul',3),
				(party_remove_members,'p_main_party','trp_bandit_leader',1),
			(try_end),
			(add_xp_as_reward,1000),
			(store_random_in_range,reg0,3,6),
			(val_mul,reg0,':reward_mul'),
			(troop_add_items,'trp_player','itm_string_of_coins',reg0),
		(else_try),
			(eq,':quest_no','qst_merchant_deliver_shipment'),
			(quest_get_slot,':item_no','qst_merchant_deliver_shipment',slot_quest_item_2),
			(quest_get_slot,':item_qty','qst_merchant_deliver_shipment',slot_quest_item_2_cnt),
			(troop_remove_items,'trp_player',':item_no',':item_qty'),
			(store_random_in_range,reg0,90,100),
			(val_mul,reg0,':item_qty'),
			(add_xp_as_reward,reg0),
			(store_div,':cash_reward',':item_qty',2),
			(troop_add_items,'trp_player','itm_string_of_coins',':cash_reward'),
		(else_try),
			(eq,':quest_no','qst_merchant_establish_trading_post'),
			(store_random_in_range,reg0,900,1000),
			(add_xp_as_reward,reg0),
			(store_random_in_range,':cash_reward',5,10),
			(troop_add_items,'trp_player','itm_string_of_coins',':cash_reward'),
		(else_try),
			(eq,':quest_no','qst_merchant_negotiate_trade_contract'),
			(store_random_in_range,reg0,900,1000),
			(add_xp_as_reward,reg0),
			(store_random_in_range,':cash_reward',5,10),
			(troop_add_items,'trp_player','itm_string_of_coins',':cash_reward'),
		(try_end),
		(try_begin),
			(check_quest_active,'qst_faction_enza'),
			(assign,':za','qst_faction_enza'),
			(quest_get_slot,':za_master','qst_faction_enza',slot_quest_za_master),
		(try_begin),
			(check_quest_active,'qst_faction_ginza'),
			(assign,':za','qst_faction_ginza'),
			(quest_get_slot,':za_master','qst_faction_ginza',slot_quest_za_master),
		(try_begin),
			(check_quest_active,'qst_faction_andaza'),
			(assign,':za','qst_faction_andaza'),
			(quest_get_slot,':za_master','qst_faction_andaza',slot_quest_za_master),
		(try_end),
		(call_script,'script_object_modify_slot',obj_troop,':za_master',slot_troop_quest,op_asn,null),
		(call_script,'script_object_modify_slot',obj_troop,':za_master',slot_troop_quest_active,op_asn,false),
		(call_script,'script_modify_za_standing',':za',5),
		# (call_script,'script_end_quest',':quest_no'),
		]
	),
('merchant_quest_abort',
	[
		(store_script_param,':quest_no'),
		(try_begin),
			(check_quest_active,'qst_faction_enza'),
			(assign,':za','qst_faction_enza'),
			(quest_get_slot,':za_master','qst_faction_enza',slot_quest_za_master),
		(try_begin),
			(check_quest_active,'qst_faction_ginza'),
			(assign,':za','qst_faction_ginza'),
			(quest_get_slot,':za_master','qst_faction_ginza',slot_quest_za_master),
		(try_begin),
			(check_quest_active,'qst_faction_andaza'),
			(assign,':za','qst_faction_andaza'),
			(quest_get_slot,':za_master','qst_faction_andaza',slot_quest_za_master),
		(try_end),
		(call_script,'script_object_modify_slot',obj_troop,':za_master',slot_troop_quest,op_asn,null),
		(call_script,'script_object_modify_slot',obj_troop,':za_master',slot_troop_quest_active,op_asn,false),
		(call_script,'script_modify_za_standing',':za',-5),
		(call_script,'script_end_quest',':quest_no'),
		]
	),
# script_bushi_quest_accept
('bushi_quest_accept',
	[
		]
	),
# script_kuge_quest_accept
('kuge_quest_accept',
	[
		]
	),
# script_ronin_quest_accept
('ronin_quest_accept',
	[
		]
	),
# script_shugo_quest_reward
('quest_reward',
	[
		(store_script_param,':quest_no',1),
		(try_begin),
			  (eq,":quest_no","qst_bushi_suppress_rebels"),
			  (troop_add_gold,"trp_player",1500),
			  (add_xp_as_reward,500),
			  (call_script,'script_object_modify_slot',obj_troop,'trp_player',slot_player_renown,op_add,3),
		  (else_try),
			  (eq,":quest_no","qst_storyline_bushi_establish_outpost"),
			  (troop_add_gold,"trp_player",25000),
			  (add_xp_as_reward,2500),
			  (call_script,'script_object_modify_slot',obj_troop,'trp_player',slot_player_renown,op_add,250),
		  (else_try),
			  (eq,":quest_no","qst_storyline_bushi_rebellion"),
			  (troop_add_gold,"trp_player",35000),
			  (add_xp_as_reward,3500),
			  (call_script,'script_object_modify_slot',obj_troop,'trp_player',slot_player_renown,op_add,500),
		  (else_try),
			  (eq,":quest_no","qst_ronin_defeat_bandit_parties"),
			  (troop_add_gold,"trp_player",2500),
			  (add_xp_as_reward,1000),
			  (call_script,'script_object_modify_slot',obj_troop,'trp_player',slot_player_renown,op_add,50),
		  (else_try),
			  (eq,":quest_no","qst_ronin_apprehend_bandits"),
			  (assign,':total_prisoners',0),
			  (party_get_num_prisoner_stacks,':no_prisoner_stacks','p_main_party'),
			  (try_for_range,':stack_no',0,':no_prisoner_stacks'),
					(party_prisoner_stack_get_troop_id,':prisoner_troop_id','p_main_party',':stack_no'),
					(this_or_next|is_between,':prisoner_troop_id','trp_bandit','trp_shinobi_apprentice'),
					(eq,':prisoner_troop_id','trp_bandit_warlord'),
					(party_prisoner_stack_get_size,':num_prisoners','p_main_party',':stack_no'),
					(party_remove_prisoners,'p_main_party',':prisoner_troop_id',':num_prisoners'),
					(val_add,':total_prisoners',':num_prisoners'),
			  (try_end),
			  (store_mul,':reward',':total_prisoners',360),
			  (troop_add_gold,"trp_player",':reward'),
			  (add_xp_as_reward,500),
			  (call_script,'script_object_modify_slot',obj_troop,'trp_player',slot_player_renown,op_add,30),
		  (else_try),
			  (eq,":quest_no","qst_ronin_investigate_bandit_activity"),
			  (assign,':multiplier',1),
			  (try_begin),
				(main_party_has_troop,'trp_bandit_leader'),
				(assign,':multiplier',3),
				(party_remove_prisoners,'p_main_party','trp_bandit_leader',1),
			  (try_end),
			  (store_mul,':reward',1000,':multiplier'),
			  (troop_add_gold,"trp_player",':reward'),
			  (add_xp_as_reward,750),
			  (call_script,'script_object_modify_slot',obj_troop,'trp_player',slot_player_renown,op_add,40),
		  (else_try),
			  (eq,":quest_no","qst_storyline_bushi_enemy_patrols"),
			  (troop_add_gold,"trp_player",15000),
			  (add_xp_as_reward,2000),
			  (call_script,'script_object_modify_slot',obj_troop,'trp_player',slot_player_renown,op_add,100),
		  (else_try),
			  (eq,":quest_no","qst_bushi_defeat_enemy_local_garrisons"),
			  (store_num_parties_destroyed_by_player,reg2,"pt_local_patrol"),
			  (val_sub,reg2,"$local_patrols_defeated"),
			  (assign,reg3,500),
			  (val_mul,reg3,reg2),
			  (troop_add_gold,"trp_player",reg3),
			  (assign,reg4,250),
			  (val_mul,reg4,reg2),
			  (add_xp_as_reward,reg4),
			  (try_begin),
				  (ge,reg2,10),
				  (troop_add_item,"trp_player","itm_long_tachi",imod_watered_steel),
			  (try_end),
			  (call_script,'script_object_modify_slot',obj_troop,'trp_player',slot_player_renown,op_add,reg2),
		  (else_try),
			  (eq,":quest_no","qst_bushi_reconnoiter_enemy_army"),
			  (troop_add_gold,"trp_player",500),
			  (add_xp_as_reward,600),
			  (call_script,'script_object_modify_slot',obj_troop,'trp_player',slot_player_renown,op_add,2),
		  (else_try),
			  (eq,":quest_no","qst_bushi_reconnoiter_enemy_army"),
			  (troop_add_gold,"trp_player",300),
			  (add_xp_as_reward,450),
			  (call_script,'script_object_modify_slot',obj_troop,'trp_player',slot_player_renown,op_add,2),
		  (else_try),
			  (eq,":quest_no","qst_kuge_emissary"),
			  (troop_add_gold,"trp_player",250),
			  (add_xp_as_reward,350),
			  (call_script,'script_object_modify_slot',obj_troop,'trp_player',slot_player_renown,op_add,3),
		  (else_try),
			  (eq,":quest_no","qst_kuge_entertain_visiting_kuge"),
			  (troop_add_gold,"trp_player",750),
			  (add_xp_as_reward,1000),
			  (call_script,'script_object_modify_slot',obj_troop,'trp_player',slot_player_renown,op_add,5),
			  (assign,'$visiting_kuge',0),
		  (else_try),
				(this_or_next|eq,":quest_no","qst_kuge_war_materials"),
				(eq,":quest_no","qst_bushi_war_materials"),
				(troop_add_gold,"trp_player",250),
				(add_xp_as_reward,350),
				(call_script,'script_object_modify_slot',obj_troop,'trp_player',slot_player_renown,op_add,2),
		  (try_end),  
		]
	),
      # script modify relation
      ("modify_relation_with_player",
        [
          (store_script_param_1,':input_faction'),
          (store_script_param_2,':input_value'),
          (store_relation,reg1,':input_faction',"fac_player_faction"),
          (val_add,reg1,':input_value'),
          (set_relation,':input_faction',"fac_player_faction",reg1)]
		),
      #script get max party capacity
      ('get_party_free_capacity',
        [
			(store_script_param,':party_no',1),
			(party_get_free_companions_capacity,reg0,':party_no'),
		# (store_party_size,reg1,'p_main_party'),
          # (assign,reg0,5),
          # (store_skill_level,reg2,skl_leadership,'trp_player'),
          # (store_attribute_level,reg3,'trp_player',ca_charisma),
          # (store_mul,reg4,reg2,5),
          # (val_add,reg4,reg3),
          # (val_add,reg0,reg4),
          # (val_sub,reg0,reg1),
		  ]),
      # script determine attitude
      ('display_attitude',
        [
          (store_script_param_1,':input_attitude'),
          (try_begin),
            (eq,':input_attitude',att_generous),
            (assign,':current_party_attitude','str_att_generous'),
          (else_try),
            (eq,':input_attitude',att_friendly),
            (assign,':current_party_attitude','str_att_friendly'),
          (else_try),
            (eq,':input_attitude',att_cautious),
            (assign,':current_party_attitude','str_att_cautious'),
          (else_try),
            (eq,':input_attitude',att_secretive),
            (assign,':current_party_attitude','str_att_secretive'),
          (else_try),
            (eq,':input_attitude',att_defensive),
            (assign,':current_party_attitude','str_att_defensive'),
          (else_try),
            (eq,':input_attitude',att_offensive),
            (assign,':current_party_attitude','str_att_offensive'),
          (else_try),
            (eq,':input_attitude',att_hostile),
            (assign,':current_party_attitude','str_att_hostile'),
          (try_end),
          (str_store_string,1,':current_party_attitude'),
          (display_message,'str_attitude')]
		),
      ('print_total_number_of_parties',
        [
          (assign,reg41,0),
          (try_for_parties),
            (val_add,reg41,1),
          (try_end),
          (display_message,'str_reg41'),
        ]
		),
# script_calculate_ward_entry_point
# Can be expanded to included inns, smithies, etc.
('calculate_ward_entry_point',
	[
		(store_script_param,':target_ward',1),
		(store_script_param,':mode',2),
		(try_begin),
			(eq,':mode',ep_mode_first_entry),
			(assign,reg0,1),
		(else_try),
			(store_current_scene,':cur_ward'),
			(try_begin),
				(eq,':target_ward',':cur_ward'),
				(assign,reg0,0),
			(else_try),
				(eq,':cur_ward','scn_city_port_ward'),
				(assign,reg0,3),
			(else_try),
				(eq,':target_ward','scn_city_south_ward'),
				(try_begin),
					(eq,':cur_ward','scn_city_east_ward'),
					(assign,reg0,3),
				(else_try),
					(eq,':cur_ward','scn_city_west_ward'),
					(assign,reg0,2),
				(try_end),
			(else_try),
				(eq,':target_ward','scn_city_north_ward'),
				(try_begin),
					(eq,':cur_ward','scn_city_east_ward'),
					(assign,reg0,2),
				(else_try),
					(eq,':cur_ward','scn_city_west_ward'),
					(assign,reg0,1),
				(try_end),
			(else_try),
				(eq,':target_ward','scn_city_east_ward'),
				(try_begin),
					(eq,':cur_ward','scn_city_north_ward'),
					(assign,reg0,2),
				(else_try),
					(eq,':cur_ward','scn_city_south_ward'),
					(assign,reg0,1),
				(try_end),
			(else_try),
				(eq,':target_ward','scn_city_west_ward'),
				(try_begin),
					(eq,':cur_ward','scn_city_north_ward'),
					(assign,reg0,1),
				(else_try),
					(eq,':cur_ward','scn_city_south_ward'),
					(assign,reg0,2),
				(else_try),
					(eq,':cur_ward','scn_city_port_ward'),
					(assign,reg0,3),
				(try_end),
			(try_end),
		(try_end),
		]
	),
# script_assign_town_guard
('assign_town_guard',
	[
		(store_script_param,':faction',1),
		(store_script_param,':guard_type',2),
		(try_begin),
			(call_script,'script_cf_faction_is_ally_of_faction',':faction','fac_hosokawa'),
			(assign,':troop_fac',0),
		(else_try),
			(assign,':troop_fac',1),
		(try_end),
		(try_begin),
			(eq,':troop_fac',0),
			(try_begin),
				(eq,':guard_type',gt_outer_gate),
				(store_random_in_range,':guard',0,2),
				(try_begin),
					(eq,':guard',0),
					(assign,':guard','trp_t2_spear_samurai_h'),
				(else_try),
					(assign,':guard','trp_t2_light_cav_h'),
				(try_end),
			(else_try),
				(eq,':guard_type',gt_inner_gate),
				(assign,':guard','trp_samurai'),
			(else_try),
				(eq,':guard_type',gt_shinden_gate),
				(store_random_in_range,':guard',0,2),
				(try_begin),
					(eq,':guard',0),
					(assign,':guard','trp_t2_heavy_cav_h'),
				(else_try),
					(assign,':guard','trp_t2_light_cav_h'),
				(try_end),
			(else_try),
				(eq,':guard_type',gt_outer_gate),
				(store_random_in_range,':guard',0,2),
				(try_begin),
					(eq,':guard',0),
					(assign,':guard','trp_t2_sword_samurai_h'),
				(else_try),
					(assign,':guard','trp_t2_spear_samurai_h'),
				(try_end),
			(try_end),
		(else_try),
			(eq,':troop_fac',1),
			(try_begin),
				(eq,':guard_type',gt_outer_gate),
				(store_random_in_range,':guard',0,2),
				(try_begin),
					(eq,':guard',0),
					(assign,':guard','trp_t2_sword_samurai_y'),
				(else_try),
					(assign,':guard','trp_t2_light_cav_y'),
				(try_end),
			(else_try),
				(eq,':guard_type',gt_inner_gate),
				(assign,':guard','trp_samurai'),
			(else_try),
				(eq,':guard_type',gt_shinden_gate),
				(store_random_in_range,':guard',0,2),
				(try_begin),
					(eq,':guard',0),
					(assign,':guard','trp_t2_heavy_cav_y'),
				(else_try),
					(assign,':guard','trp_t2_light_cav_y'),
				(try_end),
			(else_try),
				(eq,':guard_type',gt_outer_gate),
				(store_random_in_range,':guard',0,2),
				(try_begin),
					(eq,':guard',0),
					(assign,':guard','trp_t2_sword_samurai_y'),
				(else_try),
					(assign,':guard','trp_t2_spear_samurai_y'),
				(try_end),
			(try_end),
		(try_end),
		(assign,reg0,':guard'),
		]
	),
# script_cf_party_is_of_template
('cf_party_is_of_template',
	[
		(store_script_param,':party',1),
		(store_script_param,':template_id',2),
		(party_get_template_id,':template',':party'),
		(eq,':template',':template_id'),
		]
	),
# script_cf_get_faction_party_of_template
('cf_get_faction_party_of_template',
	[
		(store_script_param,':faction',1),
		(store_script_param,':template',2),
		(assign,':array','trp_temp_array_a'),
		(call_script,'script_clear_temp_array',':array',250),
		(assign,':temp_array_index',0),
		(try_for_parties,':party_no'),
			(call_script,'script_cf_party_is_of_template',':party_no',':template'),
			(store_faction_of_party,':party_faction',':party_no'),
			(eq,':party_faction',':faction'),
			(call_script,'script_object_modify_slot',obj_troop,':array',':temp_array_index',op_asn,':party_no'),
		(try_end),
		(gt,':temp_array_index',0),
		(store_random_in_range,':slot_no',0,':temp_array_index'),
		(troop_get_slot,':target_party',':array',':slot_no'),
		(assign,reg0,':target_party'),
		]
	),
###################################################################################################
#################################### Behavior Functions ###################################################
###################################################################################################
# script local patrol behavior
('local_patrol_behavior',
	[
		(store_script_param,':local_patrol',1),
		(party_get_num_companions,':current_size',':local_patrol'),
		(party_get_num_prisoners,':num_prisoners',':local_patrol'),
		(party_get_slot,':size',':local_patrol',slot_spawn_size),
		(party_get_slot,':origin',':local_patrol',slot_spawn_origin),
		(store_faction_of_party,':origin_fac',':origin'),
		(store_faction_of_party,':patrol_fac',':local_patrol'),
		(val_div,':size',2),
		(try_begin),
			(neq,':origin_fac',':patrol_fac'),
			(party_set_ai_behavior,':local_patrol',ai_bhvr_attack_party),
			(party_set_ai_object,':local_patrol',':origin'),
			(party_set_slot,':origin',slot_town_siege_attacker,':local_patrol'),
		(else_try),
			(party_slot_eq,':local_patrol',slot_spawn_has_orders,1),
			(party_is_active,':local_patrol'),
			(party_is_in_town,':local_patrol',':origin'),
			(call_script,'script_party_prisoners_add_party_prisoners',':origin',':local_patrol'),
			(remove_party,':local_patrol'),
			(party_set_slot,':origin',slot_town_patrol_active,false),
			(party_set_slot,':origin',slot_town_patrol,null),
		(else_try),
			(party_slot_neq,':local_patrol',slot_spawn_has_orders,1),
			(this_or_next|gt,':num_prisoners',0),
			(lt,':current_size',':size'),
			(party_set_ai_behavior,':local_patrol',ai_bhvr_travel_to_party),
			(party_set_ai_object,':local_patrol',':origin'),
			(party_set_slot,':local_patrol',slot_spawn_has_orders,1),
		(else_try),
			(party_slot_neq,':local_patrol',slot_spawn_has_orders,1),
			(party_set_ai_behavior,':local_patrol',ai_bhvr_patrol_party),
			(party_set_ai_object,':local_patrol',':origin'),
		(try_end),
		]),
# script_faction_patrol_behavior
('faction_patrol_behavior',
	[
		(store_script_param,':patrol',1),
		(party_get_num_companions,':current_size',':patrol'),
		(party_get_num_prisoners,':num_prisoners',':patrol'),
		(party_get_slot,':origin',':patrol',slot_spawn_origin),
		(store_mul,':size_ratio',':current_size',100),
		(val_div,':size_ratio',':num_prisoners'),
		(try_begin),
			(party_slot_neq,':patrol',slot_spawn_has_orders,true),
			(le,':size_ratio',200),
			(party_set_ai_behavior,':patrol',ai_bhvr_travel_to_party),
			(party_set_ai_object,':patrol',':origin'),
			(call_script,'script_object_modify_slot',obj_party,':patrol',slot_spawn_ai_state,op_asn,spai_traveling_to_center),
			(call_script,'script_object_modify_slot',obj_party,':patrol',slot_spawn_has_orders,op_asn,true),
		(else_try),
			(party_slot_eq,':patrol',slot_spawn_has_orders,true),
			(party_is_in_town,':patrol',':origin'),
			(remove_party,':patrol'),
			(store_faction_of_party,':faction',':patrol'),
			(try_begin),
				(eq,':faction','fac_hosokawa'),
				(party_template_get_slot,':spawn_cost','pt_hosokawa_patrol',slot_template_spawn_cost),
				(val_div,':spawn_cost',2),
				(call_script,'script_object_modify_slot',obj_faction,'fac_hosokawa',slot_faction_spawn_points,op_add,':spawn_cost'),
			(else_try),
				(eq,':faction','fac_yamana'),
				(party_template_get_slot,':spawn_cost','pt_yamana_patrol',slot_template_spawn_cost),
				(val_div,':spawn_cost',2),
				(call_script,'script_object_modify_slot',obj_faction,'fac_yamana',slot_faction_spawn_points,op_add,':spawn_cost'),
			(try_end),
		(try_end),
		]
	),
      
      #script army behavior
("army_behavior",
	[
		(store_script_param_1,':input_army'),
		(party_get_slot,':army_size',':input_army',slot_army_size),
		(store_party_size_wo_prisoners,':current_size',':input_army'),
		(party_get_slot,':army_base',':input_army',slot_army_base),
		(val_div,':army_size',2),
		(try_begin),
			(le,':current_size',':army_size'),
			(try_begin),
				(get_party_ai_object,':ai_object',':input_army'),
				(eq,':ai_object',':army_base'),
				(party_is_in_town,':input_army',':ai_object'),
				(store_faction_of_party,':faction',':input_army'),
				(try_begin),
					(eq,':faction',"fac_hosokawa"),
					(call_script,"script_add_hosokawa_reinforcements",':input_army'),
				(else_try),
					(eq,':faction',"fac_yamana"),
					(call_script,"script_add_yamana_reinforcements",':input_army'),
				(try_end),
			(else_try),
				(party_set_ai_behavior,':input_army',ai_bhvr_travel_to_party),
				(party_set_ai_object,':input_army',':army_base'),
			(try_end),
		(else_try),
			(gt,':current_size',':army_size'),
			(try_begin),
				(neq,"$war_begin",1),
				(store_random_in_range,':orders',0,4),
				(try_begin),
					(eq,':orders',0),
					(party_set_ai_behavior,':input_army',ai_bhvr_hold),
				(else_try),
					(is_between,':orders',1,3),
					(party_set_ai_behavior,':input_army',ai_bhvr_patrol_party),
					(party_set_ai_object,':input_army',':army_base'),
				(else_try),
					(eq,':orders',3),
					(neg|party_is_in_town,':input_army',':army_base'),
					(party_set_ai_behavior,':input_army',ai_bhvr_travel_to_party),
					(party_set_ai_object,':input_army',':army_base'),
				(try_end),
			(else_try),
				(eq,"$war_begin",1),
				(store_random_in_range,':orders',0,2),
				(try_begin),
					(eq,':orders',0),
					(party_set_ai_behavior,':input_army',ai_bhvr_hold),
				(else_try),
					(eq,':orders',1),
					(party_set_ai_behavior,':input_army',ai_bhvr_patrol_party),
					(party_set_ai_object,':input_army',':army_base'),
				(try_end),
			(try_end),
		(try_end),
		]
	),
      
      #script add hosokawa reinforcements
      ("add_hosokawa_reinforcements",
        [
          (store_script_param_1,':input_army'),
          (store_troop_kind_count,reg1,':input_army',"trp_taisho"),
          (try_begin),
            (lt,reg1,1),
            (party_add_members,':input_army',"trp_taisho",1),
          (try_end),
          (party_add_members,':input_army',"trp_t4_heavy_cav_h",6),
          (party_add_members,':input_army',"trp_t4_light_cav_h",6),
          (party_add_members,':input_army',"trp_t3_heavy_cav_h",8),
          (party_add_members,':input_army',"trp_t4_sword_samurai_h",10),
          (party_add_members,':input_army',"trp_t4_bow_samurai_h",10),
          (party_add_members,':input_army',"trp_t3_sword_samurai_h",15),
          (party_add_members,':input_army',"trp_t2_sword_samurai_h",15),
          (party_add_members,':input_army',"trp_t3_spear_samurai_h",15),
          (party_add_members,':input_army',"trp_t3_spear_ashigaru_h",15),
          (party_add_members,':input_army',"trp_t3_bow_ashigaru_h",18),
          (party_add_members,':input_army',"trp_t2_crossbow_ashigaru_h",20),
		]),
      
      #script add yamana reinforcements
      ("add_yamana_reinforcements",
        [
          (store_script_param_1,':input_army'),
          (store_troop_kind_count,reg1,':input_army',"trp_taisho"),
          (try_begin),
            (lt,reg1,1),
            (party_add_members,':input_army',"trp_taisho",1),
          (try_end),
          (party_add_members,':input_army',"trp_t4_heavy_cav_y",6),
          (party_add_members,':input_army',"trp_t4_light_cav_y",6),
          (party_add_members,':input_army',"trp_t3_heavy_cav_y",8),
          (party_add_members,':input_army',"trp_t4_sword_samurai_y",10),
          (party_add_members,':input_army',"trp_t4_bow_samurai_y",10),
          (party_add_members,':input_army',"trp_t3_sword_samurai_y",15),
          (party_add_members,':input_army',"trp_t2_sword_samurai_y",15),
          (party_add_members,':input_army',"trp_t3_spear_samurai_y",15),
          (party_add_members,':input_army',"trp_t3_spear_ashigaru_y",15),
          (party_add_members,':input_army',"trp_t3_bow_ashigaru_y",18),
          (party_add_members,':input_army',"trp_t2_crossbow_ashigaru_y",20),
		]),
      #script patrol behavior
      ("patrol_behavior", # Set up a dialog to tell the patrol the town is taken!
        [
          (store_script_param_1,':origin'),
          (store_script_param_2,':patrol'),
          (try_begin),
            (store_faction_of_party,':current_fac',':origin'),
            (party_get_slot,':init_fac',':origin',slot_town_initial_faction),
            (neq,':current_fac',':init_fac'),
            (party_set_ai_behavior,':patrol',ai_bhvr_attack_party),
            (party_set_ai_object,':patrol',':origin'),
            (party_set_slot,':origin',slot_town_siege_attacker,':patrol'),
          (else_try),
            (store_distance_to_party_from_party,reg5,":origin",":patrol"),
            (try_begin),
              (gt,reg5,20),
              (party_set_ai_behavior,":patrol",ai_bhvr_travel_to_party),
              (party_set_ai_object,":patrol",":origin"),
            (else_try),
              (lt,reg5,5),
              (party_set_ai_behavior,":patrol",ai_bhvr_patrol_party),
              (party_set_ai_object,":patrol",":origin"),
            (try_end),
          (try_end),
		]),
      
      ###################################################################################################
      #################################### Economy/Merchant functions #############################################
      ###################################################################################################

# script_troop_remove_items
('troop_remove_items',
	[
		(store_script_param,':troop_no',1),
		(store_script_param,':item_no_1',2),
		(store_script_param,':item_no_2',3),
		(try_begin),
			(neq,':item_no_2',0),
			(troop_get_inventory_capacity,':inv_cap',':troop_no'),
			(try_for_range,':inv_slot_no',10,':inv_cap'),
				(troop_get_inventory_slot,':item_no',':troop_no',':inv_slot_no'),
				(is_between,':item_no',':item_no_1',':item_no_2'),
				(troop_remove_item,':troop_no',':item_no'),
			(try_end),
		(else_try),
			(troop_remove_item,':troop_no',':item_no_1'),
		(try_end),
		]
	),
# script_troop_add_merchandise
('troop_add_merchandise',
	[
		(store_script_param,':town',1),
		(store_script_param,':troop_no',2),
		(store_script_param,':items_begin',3),
		(store_script_param,':items_end',4),
		(store_script_param,':min_item_count',5),
		(store_script_param,':max_item_count',6),
		(store_script_param,':min_abundance',7),
		#(troop_clear_inventory,':troop_no'),
		(call_script,'script_clear_temp_array','trp_temp_array_a',250),
		(call_script,'script_clear_temp_array','trp_temp_array_b',250),
		(call_script,'script_clear_temp_array','trp_temp_array_c',250),
		(assign,':item_array','trp_temp_array_a'),
		(assign,':item_count_array','trp_temp_array_b'),
		(assign,':item_abundance_array','trp_temp_array_c'),
		(assign,':temp_array_index',0),
		(try_for_range,':item_no',':items_begin',':items_end'),
			(troop_set_slot,':item_array',':temp_array_index',':item_no'),
			(call_script,'script_calculate_abundance',':town',':item_no'),
			(assign,':item_abundance',reg0),
			(val_max,':item_abundance',':min_abundance'),
			(troop_set_slot,':item_abundance_array',':temp_array_index',':item_abundance'),
			(store_div,':item_count',':item_abundance',100),
			(troop_set_slot,':item_count_array',':temp_array_index',':item_count'),
			(val_add,':temp_array_index',1),
		(try_end),
		(assign,':temp_array_length',':temp_array_index'),
		(assign,':sum_items',0),
		(try_for_range,':temp_array_index',0,':temp_array_length'),
			(troop_get_slot,':item_count',':item_count_array',':temp_array_index'),
			(val_add,':sum_items',':item_count'),
		(try_end),
		(store_random_in_range,':num_items',':min_item_count',':max_item_count'),
		(store_mul,':ratio',':num_items',100),
		(val_div,':ratio',':sum_items'),
		(try_for_range,':temp_array_index',0,':temp_array_length'),
			(troop_get_slot,':item_count',':item_count_array',':temp_array_index'),
			(val_mul,':item_count',':ratio'),
			(val_div,':item_count',100),
			(troop_set_slot,':item_count_array',':temp_array_index',':item_count'),
		(try_end),
		(try_for_range,':temp_array_index',0,':temp_array_length'),
			(troop_slot_neq,':item_count_array',':temp_array_index',0),
			(troop_get_slot,':item_no',':item_array',':temp_array_index'),
			(troop_get_slot,':item_count',':item_count_array',':temp_array_index'),
			(troop_add_items,':troop_no',':item_no',':item_count'),
		(try_end),
		]
	),
	  # script select reapir weapon
	  # script either fails or returns the string to s3
('cf_select_repair_weapon',
	[
		(store_script_param,':troop',1),
		(store_script_param,':item_slot_no',2),
		(troop_get_inventory_slot,':item_in_slot',':troop',':item_slot_no'),
		(troop_get_inventory_slot_modifier,':item_in_slot_mod',':troop',':item_slot_no'),
		(try_begin),
			(gt,':item_in_slot','itm_no_item'),
			(assign,':script_status',1),
			(str_store_item_name,2,':item_in_slot'),
			(try_begin),
				(eq,':item_in_slot_mod',imod_watered_steel),
				(str_store_string,1,'@Watered-steel'),
			(else_try),
				(eq,':item_in_slot_mod',imod_heavy),
				(str_store_string,1,'@Heavy'),
			(else_try),
				(eq,':item_in_slot_mod',imod_balanced),
				(str_store_string,1,'@Balanced'),
			(else_try),
				(eq,':item_in_slot_mod',imod_plain),
				(str_store_string,1,'@Plain'),
			(else_try),
				(eq,':item_in_slot_mod',imod_chipped),
				(str_store_string,1,'@Chipped'),
			(else_try),
				(eq,':item_in_slot_mod',imod_bent),
				(str_store_string,1,'@Bent'),
			(else_try),
				(eq,':item_in_slot_mod',imod_rusty),
				(str_store_string,1,'@Rusty'),
			(else_try),
				(eq,':item_in_slot_mod',imod_cracked),
				(str_store_string,1,'@Cracked'),
			(else_try),
				(eq,':item_in_slot_mod',imod_old),
				(str_store_string,1,'@Old'),
			(try_end),
			(str_store_string,3,'@{s1} {s2}'),
		(else_try),
			(assign,':script_status',0),
		(try_end),
		(eq,':script_status',1),
		]
	),

# script_get_trader_dest
('get_trade_dest',
	[
		(store_script_param,':town',1),
		(party_get_slot,':dest_array',':town',slot_town_dest_array),
		(call_script,'script_array_cycle',':dest_array'),
		(assign,reg0,'$return'),
		]
	),
# script_town_add_trader_dest
('town_add_trader_dest',
	[
		(store_script_param,':town',1),
		(store_script_param,':dest',2),
		(party_get_slot,':dest_array',':town',slot_town_dest_array),
		(party_get_slot,':array_length',':dest_array',array_value_high_index),
		(assign,':dest_in_array',false),
		(try_for_range,':unused',0,':array_length'),
			(call_script,'script_array_cycle',':dest_array'),
			(eq,'$return',':dest'),
			(assign,':dest_in_array',true),
		(try_end),
		(try_begin),
			(eq,':dest_in_array',true),
		(else_try),
			(call_script,'script_array_push',':dest_array',':dest'),
			(display_message,'@Destination added to town list'),
		(try_end),
		]
	),
# script_town_remove_trader_dest
('town_remove_trader_dest',
	[
		(store_script_param,':town',1),
		(store_script_param,':dest',2),
		(party_get_slot,':dest_array',':town',slot_town_dest_array),
		(party_get_slot,':array_length',':dest_array',array_value_high_index),
		(try_for_range,':unused',0,':array_length'),
			(call_script,'script_array_queue',':dest_array'),
			(try_begin),
				(eq,'$return',':dest'),
				(display_message,'@Destination removed from town list'),
			(else_try),
				(call_script,'script_array_push',':dest_array','$return'),
			(try_end),
		(try_end),
		]
	),
# script_troop_get_item_count
('troop_get_item_count',
	[
		(store_script_param,':troop_no',1),
		(store_script_param,':item_no',2),
		(troop_get_inventory_capacity,':inv_cap',':troop_no'),
		(assign,':item_no_count',0),
		(try_for_range,':inv_index',0,':inv_cap'),
			(troop_get_inventory_slot,':inv_item_no',':troop_no',':inv_index'),
			(eq,':inv_item_no',':item_no'),
			(val_add,':item_no_count',1),
		(try_end),
		(assign,reg0,':item_no_count'),
		]
	),
# script_spawn_spawn_point
('spawn_spawn_point',
	[
		(store_script_param,':origin',1),
		(store_script_param,':pos_x',2),
		(store_script_param,':pos_y',3),
		(set_spawn_radius,0),
		(spawn_around_party,':origin','pt_spawn_point'),
		(position_set_x,pos0,':pos_x'),
		(position_set_y,pos0,':pos_y'),
		(party_set_position,reg0,pos0),
		]
	),
# script_set_trade_good_price_for_party
('set_trade_good_price_for_party',
	[	
		(store_script_param_1,':town'),
		(try_for_range,':item',trade_goods_begin,trade_goods_end),
			(store_sub,':item_price_slot',':item',trade_goods_begin),
			(val_add,':item_price_slot',slot_town_trade_good_prices_begin),
			(party_get_slot,':item_price',':town',':item_price_slot'),
			(set_price_rate_for_item,':item',':item_price'),
		(try_end),
		]
	),
			
		
      #script_generate_sales
("generate_sales",
	[
		(store_script_param,':item_no',1),
		(store_script_param,':item_no_cnt',2),
		(store_script_param,':trade_skill',3),
		(assign,reg0,-1),
		(store_mul,':guaranteed_to_sell',':item_no_cnt',':trade_skill'),
		(val_div,':guaranteed_to_sell',10),
		(assign,':total_item_inv',':item_no_cnt'),
		(val_sub,':total_item_inv',':guaranteed_to_sell'),
		(store_random_in_range,':num_to_sell',0,':total_item_inv'),
		(val_add,':num_to_sell',':guaranteed_to_sell'),
		(troop_remove_items,"trp_player",':item_no',':num_to_sell'),
		(assign,':revenue',reg0),
		(try_begin),
			(lt,':revenue',0),
			(assign,':revenue',0),
		(try_end),
		(val_mul,':revenue',6),
		(val_div,':revenue',4),
		(assign,':markup',':revenue'),
		(val_mul,':markup',':trade_skill'),
		(val_div,':markup',10),
		(val_add,':revenue',':markup'),
		(troop_add_gold,"trp_player",':revenue'),
		(assign,':xp_reward',':revenue'),
		(val_div,':xp_reward',5),
		(add_xp_as_reward,':xp_reward')
        ]
	),
      #script_calculate_abundance
      ("calculate_abundance",
        [
          (store_script_param,':town',1),
          (store_script_param,':item',2),
          (party_get_slot,':terrain',':town',slot_town_terrain),
          (party_get_slot,':size',':town',slot_town_size),
          (try_begin),
            (eq,':terrain',ter_seaside),
            (item_get_slot,':terrain_mod',':item',slot_item_seaside),
          (else_try),
            (eq,':terrain',ter_island),
            (item_get_slot,':terrain_mod',':item',slot_item_island),
          (else_try),
            (eq,':terrain',ter_lakeside),
            (item_get_slot,':terrain_mod',':item',slot_item_lakeside),
          (else_try),
            (eq,':terrain',ter_lowland),
            (item_get_slot,':terrain_mod',':item',slot_item_lowland),
          (else_try),
            (eq,':terrain',ter_highland),
            (item_get_slot,':terrain_mod',':item',slot_item_highland),
          (else_try),
            (eq,':terrain',ter_low_valley),
            (item_get_slot,':terrain_mod',':item',slot_item_low_valley),
          (else_try),
            (eq,':terrain',ter_high_valley),
            (item_get_slot,':terrain_mod',':item',slot_item_high_valley),
          (try_end),
          (try_begin),
            (eq,':size',ct_small_village),
            (item_get_slot,':size_mod',':item',slot_item_small_village),
          (else_try),
            (eq,':size',ct_village),
            (item_get_slot,':size_mod',':item',slot_item_village),
          (else_try),
            (eq,':size',ct_large_village),
            (item_get_slot,':size_mod',':item',slot_item_large_village),
          (else_try),
            (eq,':size',ct_town),
            (item_get_slot,':size_mod',':item',slot_item_town),
          (else_try),
            (eq,':size',ct_large_town),
            (item_get_slot,':size_mod',':item',slot_item_large_town),
          (else_try),
            (eq,':size',ct_city),
            (item_get_slot,':size_mod',':item',slot_item_city),
          (else_try),
            (eq,':size',ct_port),
            (item_get_slot,':size_mod',':item',slot_item_port),
          (try_end),
          (try_begin),
            (eq,"$g_month",1),
            (item_get_slot,':date_mod',':item',slot_item_jan),
          (else_try),
            (eq,"$g_month",2),
            (item_get_slot,':date_mod',':item',slot_item_feb),
          (else_try),
            (eq,"$g_month",3),
            (item_get_slot,':date_mod',':item',slot_item_mar),
          (else_try),
            (eq,"$g_month",4),
            (item_get_slot,':date_mod',':item',slot_item_apr),
          (else_try),
            (eq,"$g_month",5),
            (item_get_slot,':date_mod',':item',slot_item_may),
          (else_try),
            (eq,"$g_month",6),
            (item_get_slot,':date_mod',':item',slot_item_jun),
          (else_try),
            (eq,"$g_month",7),
            (item_get_slot,':date_mod',':item',slot_item_jul),
          (else_try),
            (eq,"$g_month",8),
            (item_get_slot,':date_mod',':item',slot_item_aug),
          (else_try),
            (eq,"$g_month",9),
            (item_get_slot,':date_mod',':item',slot_item_sep),
          (else_try),
            (eq,"$g_month",10),
            (item_get_slot,':date_mod',':item',slot_item_oct),
          (else_try),
            (eq,"$g_month",11),
            (item_get_slot,':date_mod',':item',slot_item_nov),
          (else_try),
            (eq,"$g_month",12),
            (item_get_slot,':date_mod',':item',slot_item_dec),
          (try_end),
          (assign,reg0,0),
          (val_add,reg0,':terrain_mod'),
          (val_add,reg0,':size_mod'),
          (val_mul,reg0,':date_mod'),
          (val_div,reg0,100),
        ]
      ),
	  # script rice production
('rice_production',
	[
		(store_script_param,':town',1),
		(assign,':cur_month','$g_month'),
		(party_get_slot,':town_type',':town',slot_town_size),
		(party_get_slot,':town_terrain',':town',slot_town_terrain),
		(party_get_slot,':town_production_bonus',':town',slot_town_production_bonus), # this value should change based on prevailing conditions, range is +/- 50
		# determine terrain multiplier
		(assign,':ter_mul',100),
		(try_begin),
			(this_or_next|eq,':town_terrain',ter_lowland),
			(eq,':town_terrain',ter_low_valley),
			(assign,':ter_mul',300),
		(else_try),
			(eq,':town_terrain',ter_lakeside),
			(assign,':ter_mul',200),
		(try_end),
		# determine type multiplier
		(assign,':type_mul',100),
		(try_begin),
			(this_or_next|eq,':town_type',ct_small_village),
			(eq,':town_type',ct_village),
			(assign,':type_mul',200),
		(else_try),
			(eq,':town_type',ct_large_village),
			(assign,':type_mul',300),
		(else_try),
			(eq,':town_type',ct_town),
			(assign,':type_mul',150),
		(try_end),
		# determine season multiplier
		(assign,':season_mul',100),
		(try_begin),
			(eq,':cur_month',3),
			(assign,':season_mul',250),
		(else_try),
			(eq,':cur_month',6),
			(assign,':season_mul',250),
		(else_try),
			(eq,':cur_month',4),
			(assign,':season_mul',150),
		(else_try),
			(eq,':cur_month',7),
			(assign,':season_mul',150),
		(else_try),
			(this_or_next|eq,':cur_month',0),
			(this_or_next|eq,':cur_month',1),
			(eq,':cur_month',11),
			(assign,':season_mul',25),
		(try_end),
		# get final multiplier
		(assign,':prod_mul',1),
		(val_mul,':prod_mul',':ter_mul'),
		(val_mul,':prod_mul',':type_mul'),
		(val_mul,':prod_mul',':season_mul'),
		(val_div,':prod_mul',1000000),
		(store_random_in_range,':base_rice_production',20,41),
		(val_add,':base_rice_production',':town_production_bonus'),
		(store_mul,':total_rice_production',':base_rice_production',':prod_mul'),
		(val_mul,':total_rice_production',360),
		(call_script,'script_object_modify_slot',obj_party,':town',slot_town_food_stores,op_add,':total_rice_production'),
		]
	),
# script_rice_comsumption
('rice_consumption',
	[
		(store_script_param,':party',1),
		# get party type
		(party_get_slot,':party_type',':party',slot_party_type),
		(try_begin),
			(eq,':party_type',spt_city),
			(party_get_slot,':city_size',':party',slot_town_size),
			(party_get_slot,':available_rice',':party',slot_town_food_stores),
			(val_sub,':available_rice',':city_size'),
			(val_max,':available_rice',0),
			(party_set_slot,':party',slot_town_food_stores,':available_rice'),
		(else_try),
			(this_or_next|eq,':party_type',spt_patrol),
			(eq,':party_type',spt_army),
			(party_get_num_companions,':party_size',':party'),
			(party_get_slot,':available_rice',':party',slot_party_food),
			(val_sub,':available_rice',':party_size'),
			(val_max,':available_rice',0),
			(party_set_slot,':party',slot_party_food,':available_rice'),
		(try_end),
		]
	),

#script set item prices - to be called by the city/town/village game menu
      ("set_item_prices",
        [
          (store_script_param_1,":town"),
          (party_get_slot,':export_good',':town',slot_town_export_good), #sells cheap
          (party_get_slot,':import_good',':town',slot_town_import_good), #buys high
          (party_get_slot,':export_rate',':town',slot_town_export_rate),
          (party_get_slot,':import_rate',':town',slot_town_import_rate),
          (party_get_slot,':import_demand',':town',slot_town_import_demand),
          (party_get_slot,':export_demand',':town',slot_town_export_demand),
          (try_begin),
            (eq,':import_demand',1),
            (assign,"$import_demand_multiplier",1),
            (assign,"$import_demand_divisor",2),
          (else_try),
            (eq,':import_demand',2),
            (assign,"$import_demand_multiplier",3),
            (assign,"$import_demand_divisor",4),
          (else_try),
            (eq,':import_demand',3),
            (assign,"$import_demand_multiplier",1),
            (assign,"$import_demand_divisor",1),
          (else_try),
            (eq,':import_demand',4),
            (assign,"$import_demand_multiplier",3),
            (assign,"$import_demand_divisor",2),
          (else_try),
            (eq,':import_demand',5),
            (assign,"$import_demand_multiplier",2),
            (assign,"$import_demand_divisor",1),
          (try_end),
          (try_begin),
            (eq,':export_demand',1),
            (assign,"$export_demand_multiplier",1),
            (assign,"$export_demand_divisor",2),
          (else_try),
            (eq,':export_demand',2),
            (assign,"$export_demand_multiplier",3),
            (assign,"$export_demand_divisor",4),
          (else_try),
            (eq,':export_demand',3),
            (assign,"$export_demand_multiplier",1),
            (assign,"$export_demand_divisor",1),
          (else_try),
            (eq,':export_demand',4),
            (assign,"$export_demand_multiplier",3),
            (assign,"$export_demand_divisor",2),
          (else_try),
            (eq,':export_demand',5),
            (assign,"$export_demand_multiplier",2),
            (assign,"$export_demand_divisor",1),
          (try_end),
          (val_mul,':export_rate',"$export_demand_multiplier"),
          (val_div,':export_rate',"$export_demand_divisor"),
          (val_mul,':import_rate',"$import_demand_multiplier"),
          (val_div,':import_rate',"$import_demand_divisor"),
          (reset_price_rates),
          (set_price_rate_for_item,':export_good',':export_rate'),
          (set_price_rate_for_item,':import_good',':import_rate'),
      ]),
      
#script_demand - to be called by the  semi-weekly trigger
('demand',
	[
		(try_for_range,':input_city',hyogo,villages_end),
            (party_get_slot,':import_demand',":input_city",slot_town_import_demand),
            (store_random_in_range,':fluctuation',-1,2),
			(val_add,':import_demand',':fluctuation'),
			(val_clamp,':import_demand',1,6),
            (party_set_slot,":input_city",slot_town_import_demand,':import_demand'),
            (party_get_slot,':export_demand',":input_city",slot_town_export_demand),
            (party_get_slot,reg3,":input_city",slot_town_trade_month),
            (store_random_in_range,':fluctuation',-1,2),
			(val_add,':export_demand',':fluctuation'),
			(val_clamp,':export_demand',1,6),
            (try_begin),
				(eq,reg3,"$g_month"),
				(val_sub,':export_demand',1),
				(val_clamp,':export_demand',1,6),
            (try_end),
            (party_set_slot,":input_city",slot_town_export_demand,':export_demand'),
			(party_get_slot,':demand',":input_city",slot_town_demand),
            (store_random_in_range,':fluctuation',-2,3),
			(val_add,':fluctuation',1),
			(val_add,':demand',':fluctuation'),
			(val_clamp,':demand',-50,51),
            (party_set_slot,":input_city",slot_town_demand,':demand'),
		(try_end),
        ]
	),
# script_generate_base_revenue
      ('generate_base_revenue',
        [
          (store_script_param_1,':town'),
          (party_get_slot,':town_size',':town',slot_town_size),
          (try_begin),
            (eq,':town_size',ct_small_village),
            (assign,':base_revenue',360),
          (else_try),
            (eq,':town_size',ct_village),
            (assign,':base_revenue',720),
          (else_try),
            (eq,':town_size',ct_large_village),
            (assign,':base_revenue',1800),
          (else_try),
            (eq,':town_size',ct_town),
            (assign,':base_revenue',3600),
          (else_try),
            (eq,':town_size',ct_large_town),
            (assign,':base_revenue',7200),
          (else_try),
            (eq,':town_size',ct_port),
            (assign,':base_revenue',36000),
          (else_try),
            (eq,':town_size',ct_city),
            (assign,':base_revenue',36000),
          (try_end),
          (store_div,':revenue',':base_revenue',7),
		  (store_div,':daily_spawn_points',':base_revenue',100),
		  (call_script,'script_object_modify_slot',obj_party,':town',slot_town_treasury,op_add,':revenue'),
          (call_script,'script_object_modify_slot',obj_party,':town',slot_town_spawn_points,op_add,':daily_spawn_points'),
        ]
      ),
# script_get_trade_revenue
('get_trade_revenue',
	[
		(store_script_param,':trader',1),
		(store_script_param,':town',2),
		(party_get_template_id,':template',':trader'),
		(try_begin),
			(eq,':template','pt_traveling_farmers'),
			(party_get_slot,':gross_revenue',':trader',slot_spawn_food),
			(party_set_slot,':trader',slot_spawn_food,0),
			(call_script,'script_town_collect_taxes',':town',':gross_revenue'),
			(assign,':net_revenue',reg0),
			(party_set_slot,':trader',slot_spawn_gold,':net_revenue'),
			(call_script,'script_object_modify_slot',obj_party,':town',slot_town_food_stores,op_add,':gross_revenue'),
		(else_try),
			(eq,':template','pt_traveling_peddler'),
			(party_get_slot,':gross_revenue',':trader',slot_spawn_food),
			(party_set_slot,':trader',slot_spawn_food,0),
			(store_random_in_range,reg1,1,4),
			(val_mul,':gross_revenue',reg1),
			(call_script,'script_town_collect_taxes',':town',':gross_revenue'),
			(assign,':net_revenue',reg0),
			(party_set_slot,':trader',slot_spawn_gold,':net_revenue'),
			(call_script,'script_object_modify_slot',obj_party,':town',slot_town_food_stores,op_add,':gross_revenue'),
		(try_end),
		]
	),
('generate_trade_revenue',
	[
		(store_script_param_1,':town'),
		(store_script_param_2,':trader'),
		(store_faction_of_party,':faction',':town'),
		(try_begin),
			(call_script,'script_cf_faction_is_ally_of_faction',':faction','fac_hosokawa'),
			(assign,':target_faction','fac_hosokawa'),
		(else_try),
			(assign,':target_faction','fac_yamana'),
		(try_end),
		(party_get_slot,':revenue',':trader',slot_spawn_gold),
		(party_get_slot,':town_size',':town',slot_town_size),
		(party_get_slot,':td',':trader',slot_spawn_td_obj),
		(try_begin),
			(eq,':town_size',ct_small_village),
			(assign,':multiplier',110),
		(else_try),
			(eq,':town_size',ct_village),
			(assign,':multiplier',125),
		(else_try),
			(eq,':town_size',ct_large_village),
			(assign,':multiplier',150),
		(else_try),
			(eq,':town_size',ct_town),
			(assign,':multiplier',200),
		(else_try),
			(eq,':town_size',ct_large_town),
			(assign,':multiplier',250),
		(else_try),
			(eq,':town_size',ct_port),
			(assign,':multiplier',500),
		(else_try),
			(eq,':town_size',ct_city),
			(assign,':multiplier',350),
		(try_end),
		(val_mul,':revenue',':multiplier'),
		(val_div,':revenue',100),
		(store_div,':trade_spawn_points',':revenue',1000),
		(call_script,'script_process_trade_dest',':town',':revenue',':td'),
		(assign,':revenue',reg0),
		(call_script,'script_object_modify_slot',obj_party,':town',slot_town_treasury,op_add,':revenue'),
		(call_script,'script_object_modify_slot',obj_party,':town',slot_town_spawn_points,op_add,':trade_spawn_points'),
		(call_script,'script_object_modify_slot',obj_faction,':target_faction',slot_faction_spawn_points,op_add,':trade_spawn_points'),
		]
	),
# script town_collect taxes
# inputs: :town and revenue from trading
# outputs: net revenue to reg0
('town_collect_taxes',
	[
		(store_script_param,':town',1),
		(store_script_param,':gross_revenue',2),
		(party_get_slot,':tax_rate',':town',slot_town_tax_rate),
		(store_mul,':taxes',':gross_revenue',':tax_rate'),
		(val_div,':taxes',1000),
		(store_sub,reg0,':gross_revenue',':taxes'),
		(party_get_slot,':acc_taxes',':town',slot_town_accumulated_tariffs),
		(val_add,':acc_taxes',':taxes'),
		(party_set_slot,':town',slot_town_accumulated_tariffs,':acc_taxes'),
		(str_store_party_name,1,':town'),
		]
	),
##################### Trade Destination Scripts ##########################
# script_clear_temp_array
('clear_temp_array',
	[
		(store_script_param,':temp_array',1),
		(store_script_param,':array_length',2),
		(try_for_range,':array_index',0,':array_length'),
			(call_script,'script_object_modify_slot',obj_troop,':temp_array',':array_index',op_asn,0),
		(try_end),
		]
	),
# script_create_trade_dest
('create_trade_dest',
	[
		(store_script_param,':origin',1),
		(store_script_param,':dest',2),
		(set_spawn_radius,20),
		(spawn_around_party,':origin','pt_td'),
		(assign,':trade_dest',reg0),
		(store_mul,':td_id',':origin',10000),
		(val_add,':td_id',':trade_dest'),
		(call_script,'script_object_modify_slot',obj_party,':trade_dest',slot_td_origin,op_asn,':origin'),
		(call_script,'script_object_modify_slot',obj_party,':trade_dest',slot_td_dest,op_asn,':dest'),
		(call_script,'script_object_modify_slot',obj_party,':trade_dest',slot_td_id,op_asn,':trade_dest'),
		(call_script,'script_object_modify_slot',obj_party,':trade_dest',slot_td_code,op_asn,null),
		(call_script,'script_object_modify_slot',obj_party,':trade_dest',slot_td_manager,op_asn,null),
		]
	),
# script_town_init_trade_dest
('town_init_trade_dest',
	[
		(store_script_param,':origin',1),
		(store_script_param,':dest1',2),
		(store_script_param,':dest2',3),
		(store_script_param,':dest3',4),
		(store_script_param,':dest4',5),
		(store_script_param,':dest5',6),
		(store_script_param,':dest6',7),
		(call_script,'script_clear_temp_array','trp_temp_array_a',6),
		(call_script,'script_object_modify_slot',obj_troop,'trp_temp_array_a',0,op_asn,':dest1'),
		(call_script,'script_object_modify_slot',obj_troop,'trp_temp_array_a',1,op_asn,':dest2'),
		(call_script,'script_object_modify_slot',obj_troop,'trp_temp_array_a',2,op_asn,':dest3'),
		(call_script,'script_object_modify_slot',obj_troop,'trp_temp_array_a',3,op_asn,':dest4'),
		(call_script,'script_object_modify_slot',obj_troop,'trp_temp_array_a',4,op_asn,':dest5'),
		(call_script,'script_object_modify_slot',obj_troop,'trp_temp_array_a',5,op_asn,':dest6'),
		(call_script,'script_array_initialize',100),
		(assign,':dest_array','$return'),
		(try_for_range,':temp_array_index',0,6),
			(troop_slot_neq,'trp_temp_array_a',':temp_array_index',null),
			(troop_get_slot,':dest','trp_temp_array_a',':temp_array_index'),
			(call_script,'script_create_trade_dest',':origin',':dest'),
			(call_script,'script_array_push',':dest_array',reg0),
		(try_end),
		(call_script,'script_object_modify_slot',obj_party,':origin',slot_town_dest_array,op_asn,':dest_array'),
		]
	),
# script_init_quest_trade_dest
('init_quest_trade_dest',
	[
		(store_script_param,':origin',1),
		(store_script_param,':dest',2),
		(store_script_param,':benefit',3),
		(store_script_param,':fee',4),
		(party_get_slot,':trade_dest_array',':origin',slot_town_dest_array),
		(party_get_slot,':high_index',':trade_dest_array',array_value_high_index),
		(call_script,'script_create_trade_dest',':origin',':dest',':high_index'),
		(assign,':td',reg0),
		(assign,':fee_code',0),
		(try_begin),
			(eq,':benefit',td_benefit_managed),
			(try_for_range,':za','qst_faction_enza','qst_test'),
				(check_quest_active,':za'),
				(assign,':manager',':za'),
			(try_end),
			(call_script,'script_object_modify_slot',obj_party,':td',slot_td_manager,op_asn,':manager'),
		(try_end),
		(val_mul,':benefit',100),
		(val_add,':fee_code',':benefit'),
		(val_add,':fee_code',':fee'),
		(call_script,'script_object_modify_slot',obj_party,':td',slot_td_code,op_asn,':fee_code'),
		(call_script,'script_array_push',':trade_dest_array',':td'),
		]
	),
#script_process_trade_dest
('process_trade_dest',
	[
		(store_script_param,':town',1),
		(store_script_param,':gross',2),
		(store_script_param,':td',3),
		(party_get_slot,':code',':td',slot_td_code),
		(party_get_slot,':manager',':td',slot_td_manager),
		(try_begin),
			(gt,':code',0),
			(store_div,':benefit',':code',100),
			(val_mod,':code',100),
			(assign,':fee',':code'),
			(try_begin),
				(eq,':benefit',td_benefit_fixed_fee),
				(store_mul,':mon_amt',':fee',360),
				(store_sub,':net',':gross',':mon_amt'),
			(else_try),
				(eq,':benefit',td_benefit_percentage),
				(store_mul,':mon_amt',':gross',':fee'),
				(val_div,':mon_amt',100),
				(store_sub,':net',':gross',':mon_amt'),
			(else_try),
				(eq,':benefit',td_benefit_managed),
				(store_random_in_range,':multiplier',3,6),
				(val_mul,':gross',':multiplier'),
				(store_mul,':mon_amt',':gross',':fee'),
				(val_div,':mon_amt',100),
				(store_sub,':net',':gross',':mon_amt'),
			(try_end),
			(val_div,':mon_amt',2),
			(assign,reg10,':mon_amt'),
			(display_message,'@You have received {reg10} mon from a trade contract',green_text),
			(troop_add_gold,'trp_player',':mon_amt'),
			(quest_get_slot,':manager_faction',':manager',slot_quest_za_faction),
			(call_script,'script_object_modify_slot',obj_faction,':manager_faction',slot_faction_treasury,op_add,':mon_amt'),
			(assign,reg0,':net'),
		(try_end),
		]
	),
#####################   Trading post Scripts ############################
('initialize_trading_post',
	[
		(store_script_param,':town',1),
		(store_script_param,':owner',2),
		(store_script_param,':tp_time',3),
		(store_script_param,':fee_type',4),
		(store_script_param,':fee',5),
		# construct fee code
		(assign,':tp_code',tp_code_mask),
		(store_mul,':tp_time_code',':tp_time',tp_time_code_mask),
		(val_add,':tp_code',':tp_time_code'),
		(try_begin),
			(eq,':fee_type',tp_flat_fee),
			(store_mul,':fee_code',':fee',tp_fixed_fee_mask),
		(else_try),
			(assign,':fee_code',':fee'),
		(try_end),
		(val_add,':tp_code',':fee_code'),
		(set_spawn_radius,0),
		(spawn_around_party,':town','pt_trading_post'),
		(assign,':trading_post',reg0),
		(call_script,'script_object_modify_slot',obj_party,':trading_post',slot_trading_post_code,op_asn,':tp_code'),
		(call_script,'script_object_modify_slot',obj_party,':trading_post',slot_trading_post_owner,op_asn,':owner'),
		(call_script,'script_object_modify_slot',obj_party,':trading_post',slot_trading_post_hours,op_asn,0),
		(call_script,'script_object_modify_slot',obj_party,':trading_post',slot_trading_post_town,op_asn,':town'),
		(call_script,'script_object_modify_slot',obj_party,':trading_post',slot_trading_post_operator,op_asn,null),
		(call_script,'script_object_modify_slot',obj_party,':trading_post',slot_trading_post_revenue,op_asn,0),
		]
	),
('trading_post_get_time_code',
	[
		(store_script_param,':tp_code',1),
		(store_sub,':raw_code',':tp_code',tp_code_mask),
		(store_div,':time_code',':raw_code',tp_time_code_mask),
		(assign,reg0,':time_code'),
		]
	),
('trading_post_get_fee_code',
	[
		(store_script_param,':tp_code',1),
		(store_sub,':raw_code',':tp_code',tp_code_mask),
		(val_mod,':raw_code',tp_time_code_mask),
		(store_div,':fee_code',':raw_code',tp_fixed_fee_mask),
		(try_begin),
			(eq,':fee_code',0),
			(assign,reg0,tp_percentage_fee),
			(assign,reg1,':raw_code'),
		(else_try),
			(assign,reg0,tp_flat_fee),
			(assign,reg1,':fee_code'),
		(try_end),
		]
	),
('process_trading_posts',
	[
		(store_script_param,':trading_post',1),
		(party_get_slot,':tp_code',':trading_post',slot_trading_post_code),
		(party_get_slot,':town',':trading_post',slot_trading_post_town),
		(call_script,'script_trading_post_get_time_code',':tp_code'),
		(assign,':time_code',reg0),
		(try_begin),
			(party_slot_eq,':trading_post',slot_trading_post_hours,':time_code'),
			(call_script,'script_object_modify_slot',obj_party,':trading_post',slot_trading_post_hours,op_asn,0),
			(call_script,'script_trading_post_get_fee_code',':tp_code'),
			(assign,':fee_type',reg0),
			(assign,':fee',reg1),
			(try_begin),
				(eq,':fee_type',tp_flat_fee),
				(store_mul,':total_fee',':fee',10),
				(call_script,'script_object_modify_slot',obj_party,':trading_post',slot_trading_post_revenue,op_sub,':total_fee'),
				(call_script,'script_object_modify_slot',obj_party,':town',slot_town_treasury,op_add,':total_fee'),
			(else_try),
				(party_get_slot,':tp_revenue',':trading_post',slot_trading_post_revenue),
				(store_mul,':total_fee',':tp_revenue',':fee'),
				(val_div,':total_fee',100),
				(call_script,'script_object_modify_slot',obj_party,':trading_post',slot_trading_post_revenue,op_sub,':total_fee'),
				(call_script,'script_object_modify_slot',obj_party,':town',slot_town_treasury,op_add,':total_fee'),
			(try_end),
		(try_end),
		(call_script,'script_object_modify_slot',obj_party,':trading_post',slot_trading_post_hours,op_add,1),
		(call_script,'script_trading_post_generate_revenue',':trading_post'),	
		]
	),
('trading_post_generate_revenue',
	[
		(store_script_param,':trading_post',1),
		(neg|is_currently_night),
		(party_get_slot,':operator',':trading_post',slot_trading_post_operator),
		(try_begin),
			(neq,':operator',null),
			(assign,':tp_mul',2),
		(else_try),
			(assign,':tp_mul',1),
		(try_end),
		(store_random_in_range,':gross_sales',0,100),
		(store_skill_level,':trade','trp_player',skl_trade),
		(val_mul,':gross_sales',':trade'),
		(val_mul,':gross_sales',':tp_mul'),
		(call_script,'script_object_modify_slot',obj_party,':trading_post',slot_trading_post_revenue,op_add,':gross_sales'),
		]
	),
# script_tranding_post_disburse_revenue
('trading_post_disburse_revenue',
	[
		(store_script_param,':trading_post',1),
		(assign,':disbursement',0),
		(party_get_slot,':cur_revenue',':trading_post',slot_trading_post_revenue),
		(val_div,':cur_revenue',2),
		(call_script,'script_object_modify_slot',obj_party,':trading_post',slot_trading_post_revenue,op_asn,':cur_revenue'),
		(val_add,':disbursement',':cur_revenue'),
		(assign,reg0,':disbursement'),
		],
	),
('party_trades_with_party',
	[
		(store_script_param,':town',1),
		(store_script_param,':target_town',2),
		(party_get_slot,':trade_dest_array',':town',slot_town_dest_array),
		(party_get_slot,':array_length',':trade_dest_array',array_value_high_index),
		(assign,reg0,false),
		(try_for_range,':array_index',0,':array_length'),
			(call_script,'script_array_peek',':trade_dest_array',':array_index'),
			(assign,':td_obj','$return'),
			(party_slot_eq,':td_obj',slot_td_dest,':target_town'),
			(assign,reg0,true),
		(try_end),
		]
	),
# script_cf_party_in_range_of_party
('cf_party_in_range_of_party',
	[
		(store_script_param,':party_1',1),
		(store_script_param,':party_2',2),
		(store_script_param,':max_dist',3),
		(store_distance_to_party_from_party,':dist',':party_1',':party_2'),
		(lt,':dist',':max_dist'),
		]
	),
# script_calculate_troop_outfit_cost
('calculate_troop_outfit_cost',
	[
		(store_script_param,':troop_no',1),
		(assign,':outfit_cost',0),
		(try_for_range,':inv_slot',0,9),
			(troop_get_inventory_slot,':item_no',':troop_no',':inv_slot'),
			(neq,':item_no',-1),
			(store_item_value,':item_cost',':item_no'),
			(str_store_item_name,s11,':item_no'),
			(assign,reg10,':item_cost'),
			# (display_message,'@{s11}, {reg10} mon.',debug_text),
			(val_add,':outfit_cost',':item_cost'),
		(try_end),
		(val_div,':outfit_cost',2),
		(assign,reg0,':outfit_cost'),
		]
	),
###################################################################
# MAIN ECONOMY FUNCTIONS
###################################################################
# script_town_check_supply_and_demand
# demands are dynamically calculated from population and item demand coefficient
# this is the market that the merchants repond to
('town_check_supply_and_demand',
	[
		(store_script_param,':town',1),
		# (display_message,'@Demand check running',debug_text),
		(party_get_slot,':population',':town',slot_town_population),
		(call_script,'script_clear_temp_array','trp_temp_array_a',num_trade_goods),
		(assign,':town_demands_array','trp_temp_array_a'),
		(party_get_slot,':town_storehouse_array',':town',slot_town_storehouse_array),
		(party_get_slot,':town_goods_demand_array',':town',slot_town_demand_array),
		(party_get_slot,':facilities_array',':town',slot_town_facility_array),
		# calculate the demand level for each good
		(try_for_range,':item_no',trade_goods_begin,trade_goods_end),
			(store_sub,':temp_array_index',':item_no',trade_goods_begin),
			(call_script,'script_calculate_item_demand',':item_no',':population'),
			(assign,':item_demand',reg0),
			(str_store_item_name,s11,':item_no'),
			(assign,reg10,':item_demand'),
			# (display_message,'@{s11} demand: {reg10}',debug_text),
			(troop_set_slot,':town_demands_array',':temp_array_index',':item_demand'),
		(try_end),
		# include any facility demands
		(party_get_slot,':high_index',':facilities_array',array_value_high_index),
		(call_script,'script_calculate_population_factor',':population'),
		(assign,':population_factor',reg0),
		(try_for_range,':facility_array_index',0,':high_index'),
			(call_script,'script_array_peek',':facilities_array',':facility_array_index'),
			(assign,':cur_facility','$return'),
			(party_get_slot,':facility_inputs_array',':cur_facility',slot_facility_inputs_array),
			(try_for_range,':item_index_array',0,num_trade_goods),
				(call_script,'script_array_peek',':facility_inputs_array',':item_index_array'),
				(assign,':item_input_per_unit_labor','$return'),
				(store_mul,':total_item_input',':item_input_per_unit_labor',':population_factor'),
				(val_div,':total_item_input',100),
				(call_script,'script_object_modify_slot',obj_troop,':town_demands_array',':item_index_array',op_add,':total_item_input'),
			(try_end),
		(try_end),
		# calculate the shortfall with the town stores and assign to :town_demand_goods_array
		(try_for_range,':item_no',trade_goods_begin,trade_goods_end),
			(store_sub,':temp_array_index',':item_no',trade_goods_begin),
			(call_script,'script_array_peek',':town_storehouse_array',':temp_array_index'),
			(assign,':item_no_qty','$return'),
			(troop_get_slot,':item_no_demand_level',':town_demands_array',':temp_array_index'),
			(store_sub,':item_no_shortfall',':item_no_qty',':item_no_demand_level'),
			(val_min,':item_no_shortfall',0),
			(val_abs,':item_no_shortfall'),
			(call_script,'script_array_poke',':town_goods_demand_array',':temp_array_index',':item_no_shortfall'),
		(try_end),
		# calculate goods that are surplus (excess goods not in demand)
		(call_script,'script_update_town_surplus',':town'),
		]
	),
# script_town_generate_caravan
# checks local demand against capital storehouse, and local goods against capital demands.
# the caravan can travel up to three cities away before returning home
('cf_town_generate_caravan',
	[
		(store_script_param,':town',1),
		(store_script_param,':opt',2),
		(try_begin),
			(eq,':opt',tcs_opt_deliver_goods),
			(party_get_slot,':storehouse_array',':town',slot_town_storehouse_array),
			(party_get_slot,':surplus_array',':town',slot_town_surplus_array),
			(assign,':tmp_surplus_items','trp_temp_array_c'),
			(assign,':tmp_target_dest_array','trp_temp_array_d'),
			(assign,':tmp_target_dist_array','trp_temp_array_b'),
			(assign,':temp_goods_inv_array','trp_temp_array_a'),
			(assign,':max_item_inv',0),
			(call_script,'script_clear_temp_array',':tmp_surplus_items',num_trade_goods),
			(call_script,'script_clear_temp_array',':tmp_target_dest_array',num_trade_goods),
			(call_script,'script_clear_temp_array',':tmp_target_dist_array',num_trade_goods),
			(call_script,'script_clear_temp_array',':temp_goods_inv_array',num_trade_goods),
			# populate temp surplus array
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_peek',':surplus_array',':array_index'),
				(assign,':surplus_qty','$return'),
				(troop_set_slot,':tmp_surplus_items',':array_index',':surplus_qty'),
			(try_end),
			# get highest quanity
			(assign,':max_item_inv',0),
			(try_for_range,':array_index',0,num_trade_goods),
				(troop_get_slot,':cur_surplus_qty',':tmp_surplus_items',':array_index'),
				(val_max,':max_item_inv',':cur_surplus_qty'),
			(try_end),
			# get the highest quantity of supply goods from the list
			(try_for_range,':temp_array_index',0,num_trade_goods),
				(troop_slot_eq,':tmp_surplus_items',':temp_array_index',':max_item_inv'),
				(assign,':target_array_index',':temp_array_index'),
			(try_end),
			# get a list of towns that demand the target item
			(assign,':temp_array_index',0),
			(try_for_range,':target_town',cities_begin,villages_end),
				(party_get_slot,':demand_array',':target_town',slot_town_demand_array),
				(call_script,'script_array_peek',':demand_array',':target_array_index'),
				(assign,':itm_demand','$return'),
				(gt,':itm_demand',0),
				(str_store_party_name,s11,':target_town'),
				(display_message,'@Demand town: {s11}',debug_text),
				(troop_set_slot,':tmp_target_dest_array',':temp_array_index',':target_town'),
				(val_add,':temp_array_index',1),
			(try_end),
			# populate the distance array
			(assign,':temp_array_length',':temp_array_index'),
			(try_for_range,':temp_array_index',0,':temp_array_length'),
				(troop_get_slot,':target_dest',':tmp_target_dest_array',':temp_array_index'),
				(store_distance_to_party_from_party,':dist',':town',':target_dest'),
				(str_store_party_name,s11,':target_dest'),
				(assign,reg10,':dist'),
				(display_message,'@Dist to town: {s11}, {reg10}',debug_text),
				(troop_set_slot,':tmp_target_dist_array',':temp_array_index',':dist'),
			(try_end),
			# get closest location
			(assign,':target_dist',100000),
			(assign,':target_dest_array_index',0),
			(try_for_range,':temp_array_index',0,':temp_array_length'),
				(troop_get_slot,':cur_dist',':tmp_target_dist_array',':temp_array_index'),
				(le,':cur_dist',':target_dist'),
				(assign,':target_dist',':cur_dist'),
				(assign,':target_dest_array_index',':temp_array_index'),
			(try_end),
			(troop_get_slot,':dest',':tmp_target_dest_array',':target_dest_array_index'),
			(troop_set_slot,':temp_goods_inv_array',':target_array_index',':max_item_inv'),
			(store_add,':max_item_no',':target_array_index',trade_goods_begin),
			(neq,':dest','p_main_party'),
			(str_store_party_name,s11,':dest'),
			(str_store_item_name,s12,':max_item_no'),
			(assign,reg10,':max_item_inv'),
			(display_message,'@Caravan dest: {s11}',debug_text),
			# remove item from store house
			(call_script,'script_array_modify_value',':storehouse_array',':target_array_index',op_sub,':max_item_inv'),
			(call_script,'script_array_modify_value',':surplus_array',':target_array_index',op_asn,0),
			(call_script,'script_array_peek',':storehouse_array',':target_array_index'),
			(assign,reg11,'$return'),
			(display_message,'@Remaining surplus inv: {s12}, {reg11}',debug_text),
			(call_script,'script_update_town_surplus',':town'),
			# spawn caravan
			(set_spawn_radius,0),
			(spawn_around_party,':town','pt_trade_caravan'),
			(assign,':caravan',reg0),
			(call_script,'script_array_initialize',num_trade_goods),
			(assign,':caravan_goods_demand_array','$return'),
			(call_script,'script_array_initialize',num_trade_goods),
			(assign,':caravan_goods_inv_array','$return'),
			(call_script,'script_array_copy_from_temp',':caravan_goods_inv_array',':temp_goods_inv_array'),
			(party_set_ai_behavior,':caravan',ai_bhvr_travel_to_party),
			(party_set_ai_object,':caravan',':dest'),
			(party_set_slot,':caravan',slot_spawn_type,spt_merchant),
			(party_set_slot,':caravan',slot_spawn_ai_state,spai_traveling_to_center),
			(party_set_slot,':caravan',slot_spawn_ai_object,':dest'),
			(party_set_slot,':caravan',slot_spawn_icon,'icon_mule'),
			(party_set_slot,':caravan',slot_spawn_origin,':town'),
			(party_set_slot,':caravan',slot_spawn_dest,':dest'),
			(party_set_slot,':caravan',slot_spawn_orders,orders_caravan_deliver_goods),
			(party_set_slot,':caravan',slot_spawn_caravan_demand_array,':caravan_goods_demand_array'),
			(party_set_slot,':caravan',slot_spawn_caravan_inv_array,':caravan_goods_inv_array'),
			(party_set_slot,':caravan',slot_spawn_att_to_player,att_cautious),
			(party_set_slot,':caravan',slot_spawn_caravan_distance,0),
			(display_message,'@Goods delivery caravan spawned: {reg10} {s12} to {s11}',debug_text),
		(else_try),
			(party_get_slot,':capital',':town',slot_town_capital),
			(try_begin),
				(eq,':town',':capital'),
				(call_script,'script_get_nearest_capital',':town','trp_temp_array_c',null),
				(assign,':capital',reg0),
			(try_end),
			(party_get_slot,':origin_storehouse_array',':town',slot_town_storehouse_array),
			(party_get_slot,':origin_demand_array',':town',slot_town_demand_array),
			(party_get_slot,':dest_storehouse_array',':capital',slot_town_storehouse_array),
			(party_get_slot,':dest_demand_array',':capital',slot_town_demand_array),
			(call_script,'script_compare_supply_demand','trp_temp_array_a',':origin_storehouse_array',':dest_demand_array'),
			(assign,':num_local_demands',reg0),
			(call_script,'script_compare_supply_demand','trp_temp_array_b',':dest_storehouse_array',':origin_demand_array'),
			(assign,':num_local_supplies',reg0),
			(assign,':temp_local_supply_array','trp_temp_array_a'),
			(assign,':temp_local_demand_array','trp_temp_array_b'),
			# test code
			(assign,':caravan_orders',null),
			(try_begin),
				(gt,':num_local_demands',0),
				(gt,':num_local_supplies',0),
				(assign,':caravan_orders',orders_caravan_mutual_trade),
			(else_try),
				(gt,':num_local_demands',0),
				(assign,':caravan_orders',orders_caravan_trade),
			(else_try),
				(neq,':opt',tcs_opt_no_inquiry),
				(assign,':caravan_orders',orders_caravan_inquire),
			(try_end),
			(neq,':caravan_orders',null),
			(set_spawn_radius,0),
			(spawn_around_party,':town','pt_trade_caravan'),
			(assign,':caravan',reg0),
			(call_script,'script_array_initialize',num_trade_goods),
			(assign,':caravan_goods_demand_array','$return'),
			(call_script,'script_array_copy_from_temp',':caravan_goods_demand_array',':temp_local_demand_array'),
			(call_script,'script_array_initialize',num_trade_goods),
			(assign,':caravan_goods_inv_array','$return'),
			(call_script,'script_array_copy_from_temp',':caravan_goods_inv_array',':temp_local_supply_array'),
			(party_set_ai_behavior,':caravan',ai_bhvr_travel_to_party),
			(party_set_ai_object,':caravan',':capital'),
			(party_set_slot,':caravan',slot_spawn_type,spt_merchant),
			(party_set_slot,':caravan',slot_spawn_ai_state,spai_traveling_to_center),
			(party_set_slot,':caravan',slot_spawn_ai_object,':capital'),
			(party_set_slot,':caravan',slot_spawn_icon,'icon_mule'),
			(party_set_slot,':caravan',slot_spawn_origin,':town'),
			(party_set_slot,':caravan',slot_spawn_dest,':capital'),
			(party_set_slot,':caravan',slot_spawn_orders,':caravan_orders'),
			(party_set_slot,':caravan',slot_spawn_caravan_demand_array,':caravan_goods_demand_array'),
			(party_set_slot,':caravan',slot_spawn_caravan_inv_array,':caravan_goods_inv_array'),
			(party_set_slot,':caravan',slot_spawn_att_to_player,att_cautious),
			(party_set_slot,':caravan',slot_spawn_caravan_distance,0),
		(try_end),
		]
	),
# script_town_check_facility_production
# loops through all a town's facilities and checks for production. Production is all or nothing: if all the resources needed are not available, no production takes place
('town_check_facility_production',
	[
		(store_script_param,':town',1),
		(party_get_slot,':population',':town',slot_town_population),
		# calculate actual workforce - based on the idea that as a town grows larger, a greater fraction of the population is engaged in non production 
		# activities (age/health issues, 'creative' work, government, business bureaucracy, etc). Scaled so that the city with maximum population has only
		# 50% of its workforce engaged in production activities
		(call_script,'script_calculate_population_factor',':population'),
		(assign,':population_factor',reg0),
		(party_get_slot,':facility_array',':town',slot_town_facility_array),
		(party_get_slot,':storehouse_array',':town',slot_town_storehouse_array),
		(party_get_slot,':high_index',':facility_array',array_value_high_index),
		(assign,reg10,':high_index'),
		# (display_message,'@Num facilities: {reg10}',debug_text),
		(try_for_range,':facility_array_index',0,':high_index'),
			(call_script,'script_array_peek',':facility_array',':facility_array_index'),
			(assign,':cur_facility','$return'),
			#(party_get_slot,':facility_name',':cur_facility',slot_facility_name),
			(party_get_slot,':facility_type',':cur_facility',slot_facility_type),
			#(party_get_slot,':facility_owner',':cur_facility',slot_facility_owner),
			(party_get_slot,':facility_inputs_array',':cur_facility',slot_facility_inputs_array),
			(party_get_slot,':facility_output_array',':cur_facility',slot_facility_outputs_array),
			(call_script,'script_calculate_production_factor',':storehouse_array',':facility_inputs_array',':population_factor'),
			(assign,':production_factor',reg0),
			(try_begin),
				(eq,':facility_type',ft_farm),
				(val_max,':production_factor',20),
			(try_end),
			(try_for_range,':array_index',0,num_trade_goods),
				(store_add,':item_no',':array_index',trade_goods_begin),
				(call_script,'script_array_peek',':storehouse_array',':array_index'),
				(assign,':item_inv_qty','$return'),
				(call_script,'script_array_peek',':facility_inputs_array',':array_index'),
				(assign,':item_required_qty','$return'),
				(call_script,'script_array_peek',':facility_output_array',':array_index'),
				(assign,':item_output_qty','$return'),
				(call_script,'script_get_production_qty',':item_required_qty',':population_factor',':production_factor'),
				(assign,':total_req_qty',reg0),
				(call_script,'script_get_production_qty',':item_output_qty',':population_factor',':production_factor'),
				(assign,':total_produced_qty',reg0),
				(val_mul,':item_inv_qty',100),
				(val_sub,':item_inv_qty',':total_req_qty'),
				(val_add,':item_inv_qty',':total_produced_qty'),
				(val_div,':item_inv_qty',100),
				(val_max,':item_inv_qty',0),
				(call_script,'script_array_poke',':storehouse_array',':array_index',':item_inv_qty'),
				(try_begin),
					(eq,':item_no','itm_hemp'),
					(store_div,':aux_item_qty',':item_inv_qty',10),
					(store_sub,':aux_array_index','itm_oil',trade_goods_begin),
					(call_script,'script_array_poke',':storehouse_array',':aux_array_index',':aux_item_qty'),
				(try_end),
			(try_end),
		(try_end),
		]
	),
# script_town_calculate_population
# compares both available food and available demand goods. Script also comsumes food stores. If food < pop / 2, food is set to 0 and unrest increments
('town_calculate_population',
	[
		(store_script_param,':town',1),
		(party_get_slot,':population',':town',slot_town_population),
		(party_get_slot,':food_stores',':town',slot_town_food_stores),
		(store_div,':pop_food_ratio',':population',2),
		(try_begin),
			# check food
			(ge,':food_stores',':pop_food_ratio'),
			(call_script,'script_object_modify_slot',obj_party,':town',slot_town_food_stores,op_sub,':pop_food_ratio'),
			(call_script,'script_object_modify_slot',obj_party,':town',slot_town_unrest,op_sub,1),
			(call_script,'script_object_modify_slot',obj_party,':town',slot_town_unrest,op_max,0),
			# continue with growth algorithm
			(assign,':num_available_goods',0),
			(assign,':total_goods_demanded',0),
			(party_get_slot,':storehouse_array',':town',slot_town_storehouse_array),
			(try_for_range,':array_index',0,num_trade_goods),
				(store_add,':item_no',trade_goods_begin,':array_index'),
				(call_script,'script_array_peek',':storehouse_array',':array_index'),
				(assign,':storehouse_item_no_qty','$return'),
				(call_script,'script_calculate_item_demand',':item_no',':population'),
				(assign,':qty_item_no_demanded',reg0),
				(val_add,':total_goods_demanded',':qty_item_no_demanded'),
				(try_begin),
					(gt,':qty_item_no_demanded',':storehouse_item_no_qty'),
					(val_add,':num_available_goods',':storehouse_item_no_qty'),
					(assign,':storehouse_item_no_qty',0),
				(else_try),
					(val_add,':num_available_goods',':qty_item_no_demanded'),
					(val_sub,':storehouse_item_no_qty',':qty_item_no_demanded'),
				(try_end),
				(call_script,'script_array_poke',':storehouse_array',':array_index',':storehouse_item_no_qty'),
			(try_end),
			(store_mul,':growth_factor',':num_available_goods',100),
			(val_div,':growth_factor',':total_goods_demanded'),
			(party_set_slot,':town',slot_town_population_growth_factor,':growth_factor'),
			(call_script,'script_town_calculate_growth',':town'),
		(else_try),
			(call_script,'script_object_modify_slot',obj_party,':town',slot_town_food_stores,op_asn,0),
			(call_script,'script_object_modify_slot',obj_party,':town',slot_town_unrest,op_add,1),
		(try_end),
		]
	),
####################################################################
# ECONOMY ACTOR FUNCTIONS
####################################################################
# script_trade_caravan_behavior
('trade_caravan_behavior',
	[
		(store_script_param,':caravan',1),
		(party_get_slot,':dest',':caravan',slot_spawn_dest),
		(party_get_slot,':origin',':caravan',slot_spawn_origin),
		(party_get_slot,':orders',':caravan',slot_spawn_orders),
		(party_get_slot,':caravan_goods_demand_array',':caravan',slot_spawn_caravan_demand_array),
		(party_get_slot,':caravan_goods_inv_array',':caravan',slot_spawn_caravan_inv_array),
		(try_begin),
			(eq,':orders',orders_caravan_trade),
			(party_is_in_town,':dest'),
			(party_get_slot,':storehouse_array',':origin',slot_town_storehouse_array),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_peek',':caravan_goods_demand_array',':array_index'),
				(assign,':demand_qty','$return'),
				(call_script,'script_array_peek',':storehouse_array',':array_index'),
				(assign,':storehouse_qty','$return'),
				(try_begin),
					(gt,':demand_qty',':storehouse_qty'),
					(assign,':qty_sold',':storehouse_qty'),
					(assign,':storehouse_qty',0),
				(else_try),
					(assign,':qty_sold',':demand_qty'),
					(val_sub,':storehouse_qty',':demand_qty'),
				(try_end),
				(call_script,'script_array_poke',':storehouse_array',':array_index',':storehouse_qty'),
				(call_script,'script_array_poke',':caravan_goods_inv_array',':array_index',':qty_sold'),
			(try_end),
			(call_script,'script_caravan_generate_trade_revenue',':caravan',gtr_trading),
			(party_set_ai_behavior,':caravan',ai_bhvr_travel_to_party),
			(party_set_ai_object,':caravan',':origin'),
			(party_set_slot,':caravan',slot_spawn_ai_object,':origin'),
			(assign,reg20,':origin'),
			# (display_message,'@Caravan dest set as party no. {reg20}',debug_text),
			(try_begin),
				(eq,reg20,0),
				(display_message,'@Dest should not be player party!',debug_text),
			(try_end),
			(party_set_slot,':caravan',slot_spawn_orders,orders_caravan_return),
		(else_try),
			(eq,':orders',orders_caravan_mutual_trade),
			(party_is_in_town,':caravan',':dest'),
			(call_script,'script_caravan_generate_trade_revenue',':caravan',gtr_mutual_trading),
			(party_set_ai_behavior,':caravan',ai_bhvr_travel_to_party),
			(party_set_ai_object,':caravan',':origin'),
			(party_set_slot,':caravan',slot_spawn_ai_object,':origin'),
			(assign,reg20,':origin'),
			# (display_message,'@Caravan dest set as party no. {reg20}',debug_text),
			(try_begin),
				(eq,reg20,0),
				(display_message,'@Dest should not be player party!',debug_text),
			(try_end),(party_set_slot,':caravan',slot_spawn_orders,orders_caravan_return),
		(else_try),
			(eq,':orders',orders_caravan_return),
			(party_is_in_town,':caravan',':origin'),
			(display_message,'@Caravan has returned',debug_text),
			(party_get_slot,':storehouse_array',':origin',slot_town_storehouse_array),
			(call_script,'script_caravan_generate_trade_revenue',':caravan',gtr_return),
			(call_script,'script_array_add_to_array',':storehouse_array',':caravan_goods_inv_array'),
			(call_script,'script_gc_destroy_caravan',':caravan'),
		(else_try),
			(eq,':orders',orders_caravan_inquire),
			(party_is_in_town,':caravan',':dest'),
			(call_script,'script_get_nearest_capital',':dest','trp_temp_array_c',':origin'),
			(assign,':capital',reg0),
			(party_get_slot,':capital_storehouse_array',':capital',slot_town_storehouse_array),
			(assign,':temp_capital_storehouse_array','trp_temp_array_a'),
			(call_script,'script_array_copy_to_temp',':temp_capital_storehouse_array',':capital_storehouse_array'),
			(assign,':temp_goods_demand_array','trp_temp_array_b'),
			(call_script,'script_array_copy_to_temp',':temp_goods_demand_array',':caravan_goods_demand_array'),
			(call_script,'script_compare_storehouse_with_goods_demand',':temp_capital_storehouse_array',':temp_goods_demand_array'),
			(try_begin),
				(gt,reg0,0),
				(assign,':caravan_orders',orders_caravan_trade),
			(else_try),
				(assign,':caravan_orders',orders_caravan_inquire),
			(try_end),
			(try_begin),
				(party_slot_lt,':caravan',slot_spawn_caravan_distance,3),
				(call_script,'script_object_modify_slot',obj_party,':caravan',slot_spawn_caravan_distance,op_add,1),
				(party_set_slot,':caravan',slot_spawn_orders,':caravan_orders'),
				(party_set_slot,':caravan',slot_spawn_ai_object,':capital'),
				(party_set_ai_behavior,':caravan',ai_bhvr_travel_to_party),
				(party_set_ai_object,':caravan',':capital'),
				(assign,reg20,':capital'),
				# (display_message,'@Caravan dest set as party no. {reg20}',debug_text),
				(try_begin),
					(eq,reg20,0),
					(display_message,'@Dest should not be player party!',debug_text),
				(try_end),
			(else_try),
				(party_get_slot,':origin',':caravan',slot_spawn_origin),
				(party_set_ai_behavior,':caravan',ai_bhvr_travel_to_party),
				(party_set_ai_object,':caravan',':origin'),
				(assign,reg20,':origin'),
				# (display_message,'@Caravan dest set as party no. {reg20}',debug_text),
				(try_begin),
					(eq,reg20,0),
					(display_message,'@Dest should not be player party!',debug_text),
				(try_end),
				(party_set_slot,':caravan',slot_spawn_orders,orders_caravan_return),
			(try_end),
		(else_try),
			(eq,':orders',orders_caravan_deliver_goods),
			(party_is_in_town,':caravan',':dest'),
			(party_get_slot,':storehouse_array',':dest',slot_town_storehouse_array),
			(call_script,'script_caravan_generate_trade_revenue',':caravan',gtr_trading),
			(call_script,'script_array_add_to_array',':storehouse_array',':caravan_goods_inv_array'),
			(party_set_ai_behavior,':caravan',ai_bhvr_travel_to_party),
			(party_set_ai_object,':caravan',':origin'),
			(party_set_slot,':caravan',slot_spawn_ai_object,':origin'),
			(party_set_slot,':caravan',slot_spawn_orders,orders_caravan_return),
		(try_end),
		]
	),
####################################################################
# HELPER ECONOMY FUNCTIONS
####################################################################
# script_calculate_item_demand
# calculates item demand for a given population
('calculate_item_demand',
	[
		(store_script_param,':item_no',1),
		(store_script_param,':population',2),
		(item_get_slot,':demand_coefficient',':item_no',slot_item_demand_coefficient),
		(store_mul,':item_demand',':demand_coefficient',':population'),
		(val_div,':item_demand',100000),
		(assign,reg0,':item_demand'),
		]
	),
# script_calculate_population_factor
# calculate actual workforce - based on the idea that as a town grows larger, a greater fraction of the population is engaged in non production 
# activities (age/health issues, 'creative' work, government, business bureaucracy, etc). Scaled so that the city with maximum population has only
# 50% of its workforce engaged in production activities
('calculate_population_factor',
	[
		(store_script_param,':population',1),
		(store_div,':percent',':population',2000),
		(store_mul,':workforce_percent',':population',':percent'),
		(val_div,':workforce_percent',100),
		(store_sub,':workforce',':population',':workforce_percent'),
		(store_div,':population_factor',':workforce',100),
		(assign,reg0,':population_factor'),
		]
	),
# script_compare_supply_demand
# inputs: a temp array troop, the supply array (of type pt_array), and a demand array (of type pt_array)
# return: a temp array containing the goods quantities that can be moved from the supply array to the demand array
('compare_supply_demand',
	[
		(store_script_param,':temp_array',1),
		(store_script_param,':supply_array',2),
		(store_script_param,':demand_array',3),
		(try_for_range,':temp_array_index',0,num_trade_goods),
			(troop_set_slot,':temp_array',':temp_array_index',0),
		(try_end),
		(assign,':num_matches',0),
		(try_for_range,':array_index',0,num_trade_goods),
			(call_script,'script_array_peek',':supply_array',':array_index'),
			(assign,':item_supply','$return'),
			(call_script,'script_array_peek',':demand_array',':array_index'),
			(assign,':item_demand','$return'),
			(gt,':item_supply',0),
			(gt,':item_demand',0),
			(val_add,':num_matches',1),
			(try_begin),
				(ge,':item_supply',':item_demand'),
				(assign,':item_delivered',':item_demand'),
			(else_try),
				(assign,':item_delivered',':item_supply'),
			(try_end),
			(troop_set_slot,':temp_array',':array_index',':item_delivered'),
		(try_end),
		(assign,reg0,':num_matches'),
		]
	),
# script_town_storehouse_add_items
('town_storehouse_add_items',
	[
		(store_script_param,':town',1),
		(store_script_param,':item_no',2),
		(store_script_param,':item_qty',3),
		(party_get_slot,':storehouse_array',':town',slot_town_storehouse_array),
		(store_sub,':array_index',':item_no',trade_goods_begin),
		(call_script,'script_array_peek',':storehouse_array',':array_index'),
		(assign,':storehouse_qty','$return'),
		(val_add,':storehouse_qty',':item_qty'),
		(val_max,':storehouse_qty',0),
		(call_script,'script_array_poke',':storehouse_array',':array_index',':storehouse_qty'),
		]
	),
# script_get_production_qty
('get_production_qty',
	[
		(store_script_param,':req_qty',1),
		(store_script_param,':pop_fac',2),
		(store_script_param,':prod_fac',3),
		(store_mul,':temp_qty',':req_qty',':pop_fac'),
		(val_mul,':temp_qty',':prod_fac'),
		(val_div,':temp_qty',100),
		(assign,reg0,':temp_qty'),
		]
	),
# script_process_unrest
('process_unrest',
	[
		(store_script_param,':town',1),
		(party_get_slot,':unrest',':town',slot_town_unrest),
		(store_mul,':normalized_unrest',':unrest',25),
		(try_begin),
			# unrest levels 1 - 4 : spawn a refugee party
			(is_between,':normalized_unrest',1,101),
			(store_random_in_range,':roll',0,100),
			(le,':roll',':normalized_unrest'),
			(party_get_slot,':capital',':town',slot_town_capital),
			(try_begin),
				(eq,':capital',':town'),
				(call_script,'script_get_nearest_capital',':town','trp_temp_array_c',null),
				(assign,':capital',reg0),
			(try_end),
			(set_spawn_radius,0),
			(spawn_around_party,':town','pt_refugees'),
			(assign,':refugees',reg0),
			(party_set_ai_behavior,':refugees',ai_bhvr_travel_to_party),
			(party_set_ai_object,':refugees',':capital'),
			(call_script,'script_object_modify_slot',obj_party,':town',slot_town_unrest,op_sub,1),
			(call_script,'script_object_modify_slot',obj_party,':town',slot_town_population,op_sub,':normalized_unrest'),
		(else_try),
			# unrest levels 5 - 8 : spawn a bandit party
			(is_between,':normalized_unrest',101,201),
			(store_sub,':action_chance',':normalized_unrest',100),
			(store_random_in_range,':roll',0,100),
			(le,':roll',':action_chance'),
			(set_spawn_radius,0),
			(spawn_around_party,':town','pt_bandits'),
			(assign,':bandits',reg0),
			(party_set_slot,':bandits',slot_spawn_type,spt_patrol),
			(call_script,'script_object_modify_slot',obj_party,':town',slot_town_unrest,op_sub,1),
			(call_script,'script_object_modify_slot',obj_party,':town',slot_town_population,op_sub,':normalized_unrest'),
		(else_try),
			# unrest levels 9 - 10 : spawn a bandit party AND have some chance to rebel to ikko ikki
			(ge,':normalized_unrest',201),
			(store_sub,':action_chance',':normalized_unrest',200),
			(val_div,':action_chance',10),
			(set_spawn_radius,0),
			(spawn_around_party,':town','pt_bandits'),
			(assign,':bandits',reg0),
			(party_set_slot,':bandits',slot_spawn_type,spt_patrol),
			(call_script,'script_object_modify_slot',obj_party,':town',slot_town_population,op_sub,':normalized_unrest'),
			(store_random_in_range,':roll',0,100),
			(le,':roll',':action_chance'),
			(party_set_faction,':town','fac_ikko_ikki'),
			(call_script,'script_object_modify_slot',obj_party,':town',slot_town_unrest,op_sub,3),
		(try_end),
		(call_script,'script_object_modify_slot',obj_party,':town',slot_town_unrest,op_sub,1),
		(call_script,'script_object_modify_slot',obj_party,':town',slot_town_unrest,op_max,0),
		]
	),
# script_town_calculate_growth
('town_calculate_growth',
	[
		(store_script_param,':town',1),
		(party_get_slot,':population',':town',slot_town_population),
		(party_get_slot,':population_max',':town',slot_town_population_max),
		(party_get_slot,':growth_factor',':town',slot_town_population_growth_factor),
		(store_sub,':diff',':population_max',':population'),
		(val_mul,':diff',1000),
		(val_div,':diff',':population_max'),
		(store_mul,':factor',':diff',':growth_factor'),
		(val_div,':factor',100),
		(val_add,':factor',1000),
		(store_mul,':new_population',':population',':factor'),
		(val_div,':new_population',1000),
		(party_set_slot,':town',slot_town_population,':new_population'),
		]
	),

# script_caravan_generate_trade_revenue
('caravan_generate_trade_revenue',
	[
		(store_script_param,':caravan',1),
		(store_script_param,':mode',2),
		(try_begin),
			(eq,':mode',gtr_trading),
			(assign,':cash',0),
			(party_get_slot,':caravan_goods_inv_array',':caravan',slot_spawn_caravan_inv_array),
			(party_get_slot,':dest',':caravan',slot_spawn_dest),
			(try_for_range,':array_index',0,num_trade_goods),
				(store_add,':item_no',trade_goods_begin,':array_index'),
				(call_script,'script_array_peek',':caravan_goods_inv_array',':array_index'),
				(assign,':item_no_qty','$return'),
				(store_item_value,':item_no_price',':item_no'),
				(store_mul,':revenue',':item_no_price',':item_no_qty'),
				(val_add,':cash',':revenue'),
			(try_end),
			(call_script,'script_object_modify_slot',obj_party,':caravan',slot_spawn_gold,op_add,':cash'),
			(call_script,'script_object_modify_slot',obj_party,':dest',slot_town_treasury,op_add,':cash'),
			(assign,reg11,':cash'),
			(display_message,'@Cash generated after buying goods: {reg11} mon',debug_text),
		(else_try),
			(eq,':mode',gtr_mutual_trading),
			(assign,':cash',0),
			(party_get_slot,':caravan_goods_inv_array',':caravan',slot_spawn_caravan_inv_array),
			(party_get_slot,':caravan_goods_demand_array',':caravan',slot_spawn_caravan_demand_array),
			(party_get_slot,':dest',':caravan',slot_spawn_dest),
			(party_get_slot,':dest_storehouse_array',':dest',slot_town_storehouse_array),
			(try_for_range,':array_index',0,num_trade_goods),
				(store_add,':item_no',trade_goods_begin,':array_index'),
				(call_script,'script_array_peek',':caravan_goods_inv_array',':array_index'),
				(assign,':item_no_qty','$return'),
				(gt,':item_no_qty',0),
				(store_item_value,':item_no_price',':item_no'),
				(store_mul,':revenue',':item_no_price',':item_no_qty'),
				(val_add,':cash',':revenue'),
				(call_script,'script_array_modify_value',':dest_storehouse_array',':array_index',op_add,':item_no_qty'),
				(call_script,'script_array_modify_value',':caravan_goods_inv_array',':array_index',op_sub,':item_no_qty'),
			(try_end),
			(try_for_range,':array_index',0,num_trade_goods),
				(store_add,':item_no',trade_goods_begin,':array_index'),
				(call_script,'script_array_peek',':caravan_goods_demand_array',':array_index'),
				(assign,':item_no_qty','$return'),
				(gt,':item_no_qty',0),
				(store_item_value,':item_no_price',':item_no'),
				(store_mul,':revenue',':item_no_price',':item_no_qty'),
				(val_div,':revenue',10),
				(val_add,':cash',':revenue'),
				(call_script,'script_array_modify_value',':dest_storehouse_array',':array_index',op_sub,':item_no_qty'),
				(call_script,'script_array_modify_value',':caravan_goods_inv_array',':array_index',op_add,':item_no_qty'),
			(try_end),
			(assign,reg11,':cash'),
			(display_message,'@Cash generated after buying goods: {reg11} mon',debug_text),
			(call_script,'script_object_modify_slot',obj_party,':caravan',slot_spawn_gold,op_add,':cash'),
			(call_script,'script_object_modify_slot',obj_party,':dest',slot_town_treasury,op_add,':cash'),
		(else_try),
			(eq,':mode',gtr_return),
			(party_get_slot,':origin',':caravan',slot_spawn_origin),
			(party_get_slot,':cash',':caravan',slot_spawn_gold),
			(call_script,'script_object_modify_slot',obj_party,':origin',slot_town_treasury,op_add,':cash'),
			(assign,reg11,':cash'),
			(display_message,'@Cash generated after buying goods: {reg11} mon',debug_text),
		(try_end),
		]
	),
# script_gc_destroy_caravan
('gc_destroy_caravan',
	[
		(store_script_param,':caravan',1),
		(party_get_slot,':caravan_goods_demand_array',':caravan',slot_spawn_caravan_demand_array),
		(party_get_slot,':caravan_goods_inv_array',':caravan',slot_spawn_caravan_inv_array),
		(remove_party,':caravan_goods_demand_array'),
		(remove_party,':caravan_goods_inv_array'),
		(remove_party,':caravan'),
		]
	),
# script_gc_destroy_facility
('gc_destroy_facility',
	[
		(store_script_param,':facility',1),
		(party_get_slot,':input_array',':facility',slot_facility_inputs_array),
		(party_get_slot,':output_array',':facility',slot_facility_outputs_array),
		(remove_party,':input_array'),
		(remove_party,':output_array'),
		(remove_party,':facility'),
		]
	),
# script_get_nearest_capital
('get_nearest_capital',
	[
		(store_script_param,':origin',1),
		(store_script_param,':temp_capital_array',2),
		(store_script_param,':exclude',3),
		(assign,':temp_array_index',0),
		(try_for_range,':town',cities_begin,towns_end),
			(party_slot_eq,':town',slot_town_capital,':town'),
			(neq,':town',':origin'),
			(neq,':town',':exclude'),
			(troop_set_slot,':temp_capital_array',':temp_array_index',':town'),
			(val_add,':temp_array_index',1),
		(try_end),
		(assign,':temp_array_length',':temp_array_index'),
		(assign,':capital',null),
		(assign,':cur_dist',100000),
		(try_for_range,':temp_array_index',0,':temp_array_length'),
			(troop_get_slot,':target_town',':temp_capital_array',':temp_array_index'),
			(store_distance_to_party_from_party,':dist',':target_town',':origin'),
			(lt,':dist',':cur_dist'),
			(assign,':cur_dist',':dist'),
			(assign,':capital',':target_town'),
		(try_end),
		(assign,reg0,':capital'),
		]
	),
# script_update_town_surplus
('update_town_surplus',
	[
		(store_script_param,':town',1),
		(party_get_slot,':population',':town',slot_town_population),
		(party_get_slot,':storehouse_array',':town',slot_town_storehouse_array),
		(party_get_slot,':surplus_array',':town',slot_town_surplus_array),
		(party_get_slot,':facilities_array',':town',slot_town_facility_array),
		(try_for_range,':array_index',0,num_trade_goods),
			(call_script,'script_array_poke',':surplus_array',':array_index',0),
			(call_script,'script_array_peek',':storehouse_array',':array_index'),
			(assign,':storehouse_qty','$return'),
			(gt,':storehouse_qty',0),
			(call_script,'script_array_poke',':surplus_array',':array_index',':storehouse_qty'),
		(try_end),
		(try_for_range,':item_no',trade_goods_begin,trade_goods_end),
			(call_script,'script_calculate_item_demand',':item_no',':population'),
			(assign,':item_demand',reg0),
			(gt,':item_demand',0),
			(store_sub,':array_index',':item_no',trade_goods_begin),
			(call_script,'script_array_poke',':surplus_array',':array_index',0),
		(try_end),
		(party_get_slot,':num_facilities',':facilities_array',array_value_high_index),
		(try_for_range,':facility_array_index',0,':num_facilities'),
			(call_script,'script_array_peek',':facilities_array',':facility_array_index'),
			(assign,':cur_facility','$return'),
			(party_get_slot,':facility_demand_array',':cur_facility',slot_facility_inputs_array),
			(try_for_range,':fda_index',0,num_trade_goods),
				(call_script,'script_array_peek',':facility_demand_array',':fda_index'),
				(assign,':facility_demand','$return'),
				(gt,':facility_demand',0),
				(call_script,'script_array_poke',':surplus_array',':fda_index',0),
			(try_end),
		(try_end),
		]
	),
# script_compare_storehouse_with_goods_demand
('compare_storehouse_with_goods_demand',
	[
		(store_script_param,':temp_storehouse_array',1),
		(store_script_param,':temp_goods_demand_array',1),
		(assign,':num_available_goods',0),
		(try_for_range,':temp_array_index',0,num_trade_goods),
			(troop_slot_ge,':temp_goods_demand_array',':temp_array_index',1),
			(troop_slot_ge,':temp_storehouse_array',':temp_array_index',1),
			(val_add,':num_available_goods',1),
		(try_end),
		(assign,reg0,':num_available_goods'),
		]
	),
# script_build_temp_trade_goods_array
('build_temp_trade_goods_array',
	[
		(store_script_param,':temp_array',1),
		(store_script_param,':item_1',2),
		(store_script_param,':item_1_qty',3),
		(store_script_param,':item_2',4),
		(store_script_param,':item_2_qty',5),
		(store_script_param,':item_3',6),
		(store_script_param,':item_3_qty',7),
		(store_script_param,':item_4',8),
		(store_script_param,':item_4_qty',9),
		(store_script_param,':item_5',10),
		(store_script_param,':item_5_qty',11),
		(store_script_param,':item_6',12),
		(store_script_param,':item_6_qty',13),
		(str_store_troop_name,s11,':temp_array'),
		(try_begin),
			(gt,':item_1',0),
			(store_sub,':array_index',':item_1',trade_goods_begin),
			(troop_set_slot,':temp_array',':array_index',':item_1_qty'),
		(try_end),
		(try_begin),
			(gt,':item_2',0),
			(store_sub,':array_index',':item_2',trade_goods_begin),
			(troop_set_slot,':temp_array',':array_index',':item_2_qty'),
		(try_end),
		(try_begin),
			(gt,':item_3',0),
			(store_sub,':array_index',':item_3',trade_goods_begin),
			(troop_set_slot,':temp_array',':array_index',':item_3_qty'),
		(try_end),
		(try_begin),
			(gt,':item_4',0),
			(store_sub,':array_index',':item_4',trade_goods_begin),
			(troop_set_slot,':temp_array',':array_index',':item_4_qty'),
		(try_end),
		(try_begin),
			(gt,':item_5',0),
			(store_sub,':array_index',':item_5',trade_goods_begin),
			(troop_set_slot,':temp_array',':array_index',':item_5_qty'),
		(try_end),
		(try_begin),
			(gt,':item_6',0),
			(store_sub,':array_index',':item_6',trade_goods_begin),
			(troop_set_slot,':temp_array',':array_index',':item_6_qty'),
		(try_end),
		]
	),
# script_calculate_production_factor
('calculate_production_factor',
	[
		(store_script_param,':storehouse_array',1),
		(store_script_param,':facility_inputs_array',2),
		(store_script_param,':population_factor',3),
		(assign,':production_factor',100),
		(try_for_range,':array_index',0,num_trade_goods),
			(call_script,'script_array_peek',':storehouse_array',':array_index'),
			(assign,':item_inv_qty','$return'),
			(call_script,'script_array_peek',':facility_inputs_array',':array_index'),
			(assign,':item_required_qty','$return'),
			(gt,':item_required_qty',0),
			(store_mul,':total_req_qty',':item_required_qty',':population_factor'),
			(val_mul,':item_inv_qty',100),
			(store_mul,':temp_production_factor',':item_inv_qty',100),
			(val_div,':temp_production_factor',':total_req_qty'),
			(val_min,':production_factor',':temp_production_factor'),
		(try_end),
		(assign,reg0,':production_factor'),
		]
	),
# script_initialize_facility
('initialize_facility',
	[
		(store_script_param,':town',1),
		(store_script_param,':type',2),
		(store_script_param,':name',3),
		(store_script_param,':owner',4),
		(call_script,'script_clear_temp_array','trp_temp_array_a',250),
		(call_script,'script_clear_temp_array','trp_temp_array_b',250),
		# (str_store_string,s11,':name'),
		# (display_message,'@{s11}',debug_text),
		(try_begin),
			(eq,':type',ft_farm),
			(call_script,'script_build_temp_trade_goods_array','trp_temp_array_a','itm_wooden_tools',5,'itm_metal_tools',2,0,0,0,0,0,0,0,0),
			(assign,':temp_inputs_array','trp_temp_array_a'),
			(call_script,'script_build_temp_trade_goods_array','trp_temp_array_b','itm_hemp',50,'itm_silk',10,'itm_rice',150,'itm_pickles',10,'itm_wheat',50,'itm_millet',100),
			(assign,':temp_outputs_array','trp_temp_array_b'),
		(else_try),
			(eq,':type',ft_paper_mill),
			(call_script,'script_build_temp_trade_goods_array','trp_temp_array_a','itm_hemp',25,'itm_wooden_tools',2,0,0,0,0,0,0,0,0),
			(assign,':temp_inputs_array','trp_temp_array_a'),
			(call_script,'script_build_temp_trade_goods_array','trp_temp_array_b','itm_paper',50,'itm_echizen_paper',5,0,0,0,0,0,0,0,0),
			(assign,':temp_outputs_array','trp_temp_array_b'),
		(else_try),
			(eq,':type',ft_flour_mill),
			(call_script,'script_build_temp_trade_goods_array','trp_temp_array_a','itm_wheat',5,'itm_metal_tools',1,0,0,0,0,0,0,0,0),
			(assign,':temp_inputs_array','trp_temp_array_a'),
			(call_script,'script_build_temp_trade_goods_array','trp_temp_array_b','itm_soya',50,0,0,0,0,0,0,0,0,0,0),
			(assign,':temp_outputs_array','trp_temp_array_b'),
		(else_try),
			(eq,':type',ft_lumber_mill),
			(call_script,'script_build_temp_trade_goods_array','trp_temp_array_a','itm_wooden_tools',5,'itm_metal_tools',5,0,0,0,0,0,0,0,0),
			(assign,':temp_inputs_array','trp_temp_array_a'),
			(call_script,'script_build_temp_trade_goods_array','trp_temp_array_b','itm_wood',50,'itm_charcoal',50,0,0,0,0,0,0,0,0),
			(assign,':temp_outputs_array','trp_temp_array_b'),
		(else_try),
			(eq,':type',ft_foundry),
			(call_script,'script_build_temp_trade_goods_array','trp_temp_array_a','itm_iron_ore',10,'itm_metal_tools',2,'itm_charcoal',10,'itm_copper_ore',10,0,0,0,0),
			(assign,':temp_inputs_array','trp_temp_array_a'),
			(call_script,'script_build_temp_trade_goods_array','trp_temp_array_b','itm_iron_bar',50,'itm_copper_bar',50,0,0,0,0,0,0,0,0),
			(assign,':temp_outputs_array','trp_temp_array_b'),
		(else_try),
			(eq,':type',ft_blacksmith),
			(call_script,'script_build_temp_trade_goods_array','trp_temp_array_a','itm_metal_tools',5,'itm_iron_bars',20,'itm_charcoal',100,0,0,0,0,0,0),
			(assign,':temp_inputs_array','trp_temp_array_a'),
			(call_script,'script_build_temp_trade_goods_array','trp_temp_array_b','itm_metal_tools',50,'itm_metal_housewares',10,0,0,0,0,0,0,0,0),
			(assign,':temp_outputs_array','trp_temp_array_b'),
		(else_try),
			(eq,':type',ft_weaver),
			(call_script,'script_build_temp_trade_goods_array','trp_temp_array_a','itm_wooden_tools',5,'itm_metal_tools',2,'itm_hemp',20,0,0,0,0,0,0),
			(assign,':temp_inputs_array','trp_temp_array_a'),
			(call_script,'script_build_temp_trade_goods_array','trp_temp_array_b','itm_linen',50,'itm_silk',10,0,0,0,0,0,0,0,0),
			(assign,':temp_outputs_array','trp_temp_array_b'),
		(else_try),
			(eq,':type',ft_woodshop),
			(call_script,'script_build_temp_trade_goods_array','trp_temp_array_a','itm_wooden_tools',5,'itm_metal_tools',2,'itm_wood',50,0,0,0,0,0,0),
			(assign,':temp_inputs_array','trp_temp_array_a'),
			(call_script,'script_build_temp_trade_goods_array','trp_temp_array_b','itm_furniture',3,'itm_elaborate_furniture',1,0,0,0,0,0,0,0,0),
			(assign,':temp_outputs_array','trp_temp_array_b'),
		(else_try),
			(eq,':type',ft_smokehouse),
			(call_script,'script_build_temp_trade_goods_array','trp_temp_array_a','itm_wood',5,'itm_salted_fish',50,0,0,0,0,0,0,0,0),
			(assign,':temp_inputs_array','trp_temp_array_a'),
			(call_script,'script_build_temp_trade_goods_array','trp_temp_array_b','itm_smoked_fish',50,0,0,0,0,0,0,0,0,0,0),
			(assign,':temp_outputs_array','trp_temp_array_b'),
		(else_try),
			(eq,':type',ft_potter),
			(call_script,'script_build_temp_trade_goods_array','trp_temp_array_a','itm_wooden_tools',5,'itm_metal_tools',2,0,0,0,0,0,0,0,0),
			(assign,':temp_inputs_array','trp_temp_array_a'),
			(call_script,'script_build_temp_trade_goods_array','trp_temp_array_b','itm_housewares',50,'itm_pottery',25,'itm_seto_pottery',5,'itm_elaborate_housewares',10,0,0,0,0),
			(assign,':temp_outputs_array','trp_temp_array_b'),
		(else_try),
			(eq,':type',ft_iron_mine),
			(call_script,'script_build_temp_trade_goods_array','trp_temp_array_a','itm_wooden_tools',10,'itm_metal_tools',10,0,0,0,0,0,0,0,0),
			(assign,':temp_inputs_array','trp_temp_array_a'),
			(call_script,'script_build_temp_trade_goods_array','trp_temp_array_b','itm_iron_ore',3,'itm_copper_ore',3,0,0,0,0,0,0,0,0),
			(assign,':temp_outputs_array','trp_temp_array_b'),
		(else_try),
			(eq,':type',ft_silver_mine),
			(call_script,'script_build_temp_trade_goods_array','trp_temp_array_a','itm_wooden_tools',20,'itm_metal_tools',15,0,0,0,0,0,0,0,0),
			(assign,':temp_inputs_array','trp_temp_array_a'),
			(call_script,'script_build_temp_trade_goods_array','trp_temp_array_b','itm_silver_ore',50,'itm_gold_ore',5,0,0,0,0,0,0,0,0),
			(assign,':temp_outputs_array','trp_temp_array_b'),
		(try_end),
		(set_spawn_radius,20),
		(spawn_around_party,':town','pt_facility'),
		(assign,':facility',reg0),
		(party_get_slot,':facility_array',':town',slot_town_facility_array),
		(party_set_slot,':facility',slot_facility_town,':town'),
		(party_set_slot,':facility',slot_facility_type,':type'),
		(party_set_slot,':facility',slot_facility_name,':name'),
		(party_set_slot,':facility',slot_facility_owner,':owner'),
		(call_script,'script_array_initialize',num_trade_goods),
		(assign,':required_inputs_array','$return'),
		(call_script,'script_array_initialize',num_trade_goods),
		(assign,':output_production_array','$return'),
		(call_script,'script_array_copy_from_temp',':required_inputs_array',':temp_inputs_array'),
		(call_script,'script_array_copy_from_temp',':output_production_array',':temp_outputs_array'),
		(party_set_slot,':facility',slot_facility_inputs_array,':required_inputs_array'),
		(party_set_slot,':facility',slot_facility_outputs_array,':output_production_array'),
		(call_script,'script_array_push',':facility_array',':facility'),
		]
	),
# script_initialize_starting_facilities
('initialize_starting_facilities',
	[
		# farms
		(call_script,'script_initialize_facility',yodo,ft_farm,'str_fac_farm',null),
		(call_script,'script_initialize_facility',takase,ft_farm,'str_fac_farm',null),
		(call_script,'script_initialize_facility',kishiwada,ft_farm,'str_fac_farm',null),
		(call_script,'script_initialize_facility',nara,ft_farm,'str_fac_farm',null),
		(call_script,'script_initialize_facility',takada,ft_farm,'str_fac_farm',null),
		(try_for_range,':town',villages_begin,villages_end),
			(call_script,'script_initialize_facility',':town',ft_farm,'str_fac_farm',null),
			(call_script,'script_town_storehouse_add_items',':town','itm_hemp',100),
			(call_script,'script_town_storehouse_add_items',':town','itm_oil',10),
			(call_script,'script_town_storehouse_add_items',':town','itm_wheat',100),
			(call_script,'script_town_storehouse_add_items',':town','itm_millet',100),
			(call_script,'script_town_storehouse_add_items',':town','itm_silk',10),
		(try_end),
		# iron mines
		(call_script,'script_initialize_facility',misaki,ft_iron_mine,'str_fac_iron_mine',null),
		(call_script,'script_town_storehouse_add_items',misaki,'itm_iron_ore',10),
		(call_script,'script_town_storehouse_add_items',misaki,'itm_copper_ore',10),
		(call_script,'script_initialize_facility',kishiwada,ft_iron_mine,'str_fac_iron_mine',null),
		(call_script,'script_town_storehouse_add_items',kishiwada,'itm_iron_ore',10),
		(call_script,'script_town_storehouse_add_items',misaki,'itm_copper_ore',10),
		(call_script,'script_initialize_facility',nagano,ft_iron_mine,'str_fac_iron_mine',null),
		(call_script,'script_town_storehouse_add_items',nagano,'itm_iron_ore',10),
		(call_script,'script_town_storehouse_add_items',misaki,'itm_copper_ore',10),
		(call_script,'script_initialize_facility',wakayama,ft_iron_mine,'str_fac_iron_mine',null),
		(call_script,'script_town_storehouse_add_items',wakayama,'itm_iron_ore',10),
		(call_script,'script_town_storehouse_add_items',misaki,'itm_copper_ore',10),
		(call_script,'script_initialize_facility',naga,ft_iron_mine,'str_fac_iron_mine',null),
		(call_script,'script_town_storehouse_add_items',naga,'itm_iron_ore',10),
		(call_script,'script_town_storehouse_add_items',misaki,'itm_copper_ore',10),
		(call_script,'script_initialize_facility',hashimoto,ft_iron_mine,'str_fac_iron_mine',null),
		(call_script,'script_town_storehouse_add_items',hashimoto,'itm_iron_ore',10),
		(call_script,'script_town_storehouse_add_items',misaki,'itm_copper_ore',10),
		(call_script,'script_initialize_facility',nishiyoshino,ft_iron_mine,'str_fac_iron_mine',null),
		(call_script,'script_town_storehouse_add_items',nishiyoshino,'itm_iron_ore',10),
		(call_script,'script_town_storehouse_add_items',misaki,'itm_copper_ore',10),
		(call_script,'script_initialize_facility',kawakami,ft_iron_mine,'str_fac_iron_mine',null),
		(call_script,'script_town_storehouse_add_items',kawakami,'itm_iron_ore',10),
		(call_script,'script_town_storehouse_add_items',misaki,'itm_copper_ore',10),
		(call_script,'script_initialize_facility',kawakami,ft_iron_mine,'str_fac_iron_mine',null),
		(call_script,'script_town_storehouse_add_items',kawakami,'itm_iron_ore',10),
		(call_script,'script_town_storehouse_add_items',misaki,'itm_copper_ore',10),
		(call_script,'script_initialize_facility',hiyoshi,ft_iron_mine,'str_fac_iron_mine',null),
		(call_script,'script_town_storehouse_add_items',hiyoshi,'itm_iron_ore',10),
		(call_script,'script_town_storehouse_add_items',misaki,'itm_copper_ore',10),
		# foundries
		(try_for_range,':town',towns_begin,towns_end),
			(call_script,'script_initialize_facility',':town',ft_foundry,'str_fac_foundry',null),
			(call_script,'script_town_storehouse_add_items',':town','itm_charcoal',100),
		(try_end),
		# smithies
		(try_for_range,':town',cities_begin,cities_end),
			(call_script,'script_initialize_facility',':town',ft_blacksmith,'str_fac_blacksmith',null),
			(call_script,'script_town_storehouse_add_items',':town','itm_charcoal',100),
		(try_end),
		(try_for_range,':town',villages_begin,villages_end),
			(call_script,'script_initialize_facility',':town',ft_blacksmith,'str_fac_blacksmith',null),
			(call_script,'script_town_storehouse_add_items',':town','itm_charcoal',100),
		(try_end),
		# lumber mills
		(call_script,'script_initialize_facility',nose,ft_lumber_mill,'str_fac_lumber_mill',null),
		(call_script,'script_town_storehouse_add_items',nose,'itm_wood',100),
		(call_script,'script_town_storehouse_add_items',nose,'itm_charcoal',100),
		(call_script,'script_town_storehouse_add_items',nose,'itm_metal_tools',10),
		(call_script,'script_town_storehouse_add_items',nose,'itm_wooden_tools',20),
		(call_script,'script_initialize_facility',fujidera,ft_lumber_mill,'str_fac_lumber_mill',null),
		(call_script,'script_town_storehouse_add_items',fujidera,'itm_wood',100),
		(call_script,'script_town_storehouse_add_items',fujidera,'itm_charcoal',100),
		(call_script,'script_town_storehouse_add_items',fujidera,'itm_metal_tools',10),
		(call_script,'script_town_storehouse_add_items',fujidera,'itm_wooden_tools',20),
		(call_script,'script_initialize_facility',nishiyoshino,ft_lumber_mill,'str_fac_lumber_mill',null),
		(call_script,'script_town_storehouse_add_items',nishiyoshino,'itm_wood',100),
		(call_script,'script_town_storehouse_add_items',nishiyoshino,'itm_charcoal',100),
		(call_script,'script_town_storehouse_add_items',nishiyoshino,'itm_metal_tools',10),
		(call_script,'script_town_storehouse_add_items',nishiyoshino,'itm_wooden_tools',20),
		(call_script,'script_initialize_facility',okawachi,ft_lumber_mill,'str_fac_lumber_mill',null),
		(call_script,'script_town_storehouse_add_items',okawachi,'itm_wood',100),
		(call_script,'script_town_storehouse_add_items',okawachi,'itm_charcoal',100),
		(call_script,'script_town_storehouse_add_items',okawachi,'itm_metal_tools',10),
		(call_script,'script_town_storehouse_add_items',okawachi,'itm_wooden_tools',20),
		(call_script,'script_initialize_facility',ikuno,ft_lumber_mill,'str_fac_lumber_mill',null),
		(call_script,'script_town_storehouse_add_items',ikuno,'itm_wood',100),
		(call_script,'script_town_storehouse_add_items',ikuno,'itm_charcoal',100),
		(call_script,'script_town_storehouse_add_items',ikuno,'itm_metal_tools',10),
		(call_script,'script_town_storehouse_add_items',ikuno,'itm_wooden_tools',20),
		(call_script,'script_initialize_facility',haga,ft_lumber_mill,'str_fac_lumber_mill',null),
		(call_script,'script_town_storehouse_add_items',haga,'itm_wood',100),
		(call_script,'script_town_storehouse_add_items',haga,'itm_charcoal',100),
		(call_script,'script_town_storehouse_add_items',haga,'itm_metal_tools',10),
		(call_script,'script_town_storehouse_add_items',haga,'itm_wooden_tools',20),
		(call_script,'script_initialize_facility',muraoka,ft_lumber_mill,'str_fac_lumber_mill',null),
		(call_script,'script_town_storehouse_add_items',muraoka,'itm_wood',100),
		(call_script,'script_town_storehouse_add_items',muraoka,'itm_charcoal',100),
		(call_script,'script_town_storehouse_add_items',muraoka,'itm_metal_tools',10),
		(call_script,'script_town_storehouse_add_items',muraoka,'itm_wooden_tools',20),
		(call_script,'script_initialize_facility',hidaka,ft_lumber_mill,'str_fac_lumber_mill',null),
		(call_script,'script_town_storehouse_add_items',hidaka,'itm_wood',100),
		(call_script,'script_town_storehouse_add_items',hidaka,'itm_charcoal',100),
		(call_script,'script_town_storehouse_add_items',hidaka,'itm_metal_tools',10),
		(call_script,'script_town_storehouse_add_items',hidaka,'itm_wooden_tools',20),
		(call_script,'script_initialize_facility',fukuchiyama,ft_lumber_mill,'str_fac_lumber_mill',null),
		(call_script,'script_town_storehouse_add_items',fukuchiyama,'itm_wood',100),
		(call_script,'script_town_storehouse_add_items',fukuchiyama,'itm_charcoal',100),
		(call_script,'script_town_storehouse_add_items',fukuchiyama,'itm_metal_tools',10),
		(call_script,'script_town_storehouse_add_items',fukuchiyama,'itm_wooden_tools',20),
		(call_script,'script_initialize_facility',miyama,ft_lumber_mill,'str_fac_lumber_mill',null),
		(call_script,'script_town_storehouse_add_items',miyama,'itm_wood',100),
		(call_script,'script_town_storehouse_add_items',miyama,'itm_charcoal',100),
		(call_script,'script_town_storehouse_add_items',miyama,'itm_metal_tools',10),
		(call_script,'script_town_storehouse_add_items',miyama,'itm_wooden_tools',20),
		(call_script,'script_initialize_facility',takahama,ft_lumber_mill,'str_fac_lumber_mill',null),
		(call_script,'script_town_storehouse_add_items',takahama,'itm_wood',100),
		(call_script,'script_town_storehouse_add_items',takahama,'itm_charcoal',100),
		(call_script,'script_town_storehouse_add_items',takahama,'itm_metal_tools',10),
		(call_script,'script_town_storehouse_add_items',takahama,'itm_wooden_tools',20),
		(call_script,'script_initialize_facility',ueno,ft_lumber_mill,'str_fac_lumber_mill',null),
		(call_script,'script_town_storehouse_add_items',ueno,'itm_wood',100),
		(call_script,'script_town_storehouse_add_items',ueno,'itm_charcoal',100),
		(call_script,'script_town_storehouse_add_items',ueno,'itm_metal_tools',10),
		(call_script,'script_town_storehouse_add_items',ueno,'itm_wooden_tools',20),
		
		]
	),
#######################################################################################
# SHOEN SCRIPTS
#######################################################################################

# script_initialize_shoen
('initialize_shoen',
	[
		(store_script_param,':town',1),
		(store_script_param,':broker',2),
		(set_spawn_radius,20),
		(spawn_around_party,':town','pt_shoen'),
		(assign,':shoen',reg0),
		(party_set_slot,':shoen',slot_shoen_town,':town'),
		(party_set_slot,':town',slot_town_shoen,':shoen'),
		(party_set_slot,':shoen',slot_shoen_broker,':broker'),
		(party_get_slot,':town_size',':town',slot_town_size),
		(try_begin),
			(eq,':town_size',ct_small_village),
			(assign,':shoen_size',100),
			(assign,':ipo_multiplier',10),
		(else_try),
			(eq,':town_size',ct_village),
			(assign,':shoen_size',175),
			(assign,':ipo_multiplier',12),
		(else_try),
			(eq,':town_size',ct_large_village),
			(assign,':shoen_size',250),
			(assign,':ipo_multiplier',15),
		(else_try),
			(eq,':town_size',ct_town),
			(assign,':shoen_size',325),
			(assign,':ipo_multiplier',18),
		(else_try),
			(eq,':town_size',ct_large_town),
			(assign,':shoen_size',400),
			(assign,':ipo_multiplier',22),
		(try_end),
		(party_set_slot,':shoen',slot_shoen_size,':shoen_size'),
		(party_set_slot,':shoen',slot_shoen_labor,100),
		(party_set_slot,':shoen',slot_shoen_labor_moving_avg,100),
		(call_script,'script_party_slot_store_mul',':shoen',slot_shoen_production,':shoen_size',100),
		(party_set_slot,':shoen',slot_shoen_improvement_level,1),
		(store_random_in_range,':ipo_price',4000,5000),
		(val_mul,':ipo_price',':ipo_multiplier'),
		(val_div,':ipo_price',10),
		(party_set_slot,':shoen',slot_shoen_share_price,':ipo_price'),
		(party_set_slot,':shoen',slot_shoen_share_price_moving_avg,':ipo_price'),
		(call_script,'script_party_slot_store_div',':shoen',slot_shoen_dividend,':ipo_price',10),
		(store_random_in_range,':ipo_no_shares',900,1000),
		(val_mul,':ipo_no_shares',10),
		(party_set_slot,':shoen',slot_shoen_total_shares,':ipo_no_shares'),
		(party_set_slot,':shoen',slot_shoen_outstanding_shares,':ipo_no_shares'),
		(call_script,'script_array_initialize',num_shareholders),
		(assign,':shareholders_array','$return'),
		(call_script,'script_array_initialize',num_shareholders),
		(assign,':shareholders_shares_owned_array','$return'),
		(call_script,'script_array_initialize',num_shareholders),
		(assign,':shareholders_accumulated_dividends_array','$return'),
		(call_script,'script_array_initialize',num_shareholders),
		(assign,':shareholders_dca_value_array','$return'),
		(call_script,'script_array_initialize',num_shareholders),
		(assign,':shareholders_total_capitalization_array','$return'),
		(try_for_range,':array_index',0,num_shareholders),
			(call_script,'script_array_poke',':shareholders_shares_owned_array',':array_index',0),
			(call_script,'script_array_poke',':shareholders_accumulated_dividends_array',':array_index',0),
			(call_script,'script_array_poke',':shareholders_dca_value_array',':array_index',0),
			(call_script,'script_array_poke',':shareholders_total_capitalization_array',':array_index',0),
		(try_end),
		(party_set_slot,':shoen',slot_shoen_shareholders_array,':shareholders_array'),
		(party_set_slot,':shoen',slot_shoen_shareholders_shares_owned_array,':shareholders_shares_owned_array'),
		(party_set_slot,':shoen',slot_shoen_shareholders_accumulated_dividends_array,':shareholders_accumulated_dividends_array'),
		(party_set_slot,':shoen',slot_shoen_shareholders_dca_value_array,':shareholders_dca_value_array'),
		(party_set_slot,':shoen',slot_shoen_shareholders_total_capitalization_array,':shareholders_total_capitalization_array'),
		]
	),
#script_cf_get_shoen_candidate
('cf_get_shoen_candidate',
	[
		(store_script_param,':num_iters',1),
		(store_random_in_range,':town',cities_begin,villages_end),
		(party_get_slot,':shoen',':town',slot_town_shoen),
		(assign,reg0,null),
		(try_begin),
			(eq,':shoen',null),
			(assign,reg0,':town'),
		(else_try),
			(lt,':num_iters',75),
			(val_add,':num_iters',1),
			(call_script,'script_cf_get_shoen_candidate',':num_iters'),
		(try_end),
		(neq,reg0,null),
		]
	),
# script_shoen_update_moving_averages
('shoen_update_moving_averages',
	[
		(store_script_param,':shoen',1),
		(party_get_slot,':current_labor',':shoen',slot_shoen_labor),
		(party_get_slot,':current_share_price',':shoen',slot_shoen_share_price),
		(party_get_slot,':labor_moving_avg',':shoen',slot_shoen_labor_moving_avg),
		(party_get_slot,':share_price_moving_avg',':shoen',slot_shoen_share_price_moving_avg),
		(val_mul,':labor_moving_avg',9),
		(val_add,':labor_moving_avg',':current_labor'),
		(val_div,':labor_moving_avg',10),
		(val_mul,':share_price_moving_avg',9),
		(val_add,':share_price_moving_avg',':current_share_price'),
		(val_div,':share_price_moving_avg',10),
		(party_set_slot,':shoen',slot_shoen_labor_moving_avg,':labor_moving_avg'),
		(party_set_slot,':shoen',slot_shoen_share_price_moving_avg,':share_price_moving_avg'),
		]
	),

('shoen_update_production',
	[
		(store_script_param,':shoen',1),
		(party_get_slot,':shoen_size',':shoen',slot_shoen_size),
		(party_get_slot,':shoen_labor',':shoen',slot_shoen_labor),
		(party_get_slot,':shoen_improvements',':shoen',slot_shoen_improvement_level),
		(party_get_slot,':current_production',':shoen',slot_shoen_production),
		(party_get_slot,':current_share_price',':shoen',slot_shoen_share_price),
		(store_random_in_range,':labor_fluctuation',-5,6),
		(val_add,':shoen_labor',':labor_fluctuation'),
		(val_max,':shoen_labor',0),
		(store_mul,':new_production',':shoen_size',':shoen_labor'),
		(val_mul,':new_production',':shoen_improvements'),
		(store_mul,':price_factor',':new_production',1000),
		(val_div,':price_factor',':current_production'),
		(store_mul,':new_share_price',':current_share_price',':price_factor'),
		(val_div,':new_share_price',1000),
		# (str_store_party_name,10,':shoen'),
		# (assign,reg10,':current_production'),
		# (assign,reg11,':current_share_price'),
		# (assign,reg12,':new_production'),
		# (assign,reg13,':price_factor'),
		# (assign,reg14,':new_share_price'),
		# (display_message,'@{s10} shoen update: cur prod: {reg10}, cur price: {reg11}, new prod: {reg12}, price factor: {reg13}, new price: {reg14}'),
		(party_set_slot,':shoen',slot_shoen_labor,':shoen_labor'),
		(party_set_slot,':shoen',slot_shoen_production,':new_production'),
		(party_set_slot,':shoen',slot_shoen_share_price,':new_share_price'),
		]
	),
# script_shoen_pay_dividends
('shoen_pay_dividends',
	[
		(store_script_param,':shoen',1),
		(party_get_slot,':per_share_dividend',':shoen',slot_shoen_dividend),
		(party_get_slot,':shareholders_array',':shoen',slot_shoen_shareholders_array),
		(party_get_slot,':shareholders_shares_owned_array',':shoen',slot_shoen_shareholders_shares_owned_array),
		(party_get_slot,':shareholders_accumulated_dividends_array',':shoen',slot_shoen_shareholders_accumulated_dividends_array),
		(try_for_range,':array_index',0,num_shareholders),
			(call_script,'script_array_peek',':shareholders_array',':array_index'),
			(assign,':shareholder','$return'),
			(ge,':shareholder',0),
			(call_script,'script_array_peek',':shareholders_shares_owned_array',':array_index'),
			(assign,':shares_owned','$return'),
			(call_script,'script_array_peek',':shareholders_accumulated_dividends_array',':array_index'),
			(assign,':accumulated_dividends','$return'),
			(store_mul,':dividend',':shares_owned',':per_share_dividend'),
			(val_add,':accumulated_dividends',':dividend'),
			(call_script,'script_array_poke',':shareholders_accumulated_dividends_array',':array_index',':accumulated_dividends'),
		(try_end),
		]
	),
	
('shoen_set_dividend',
	[
		(store_script_param,':shoen',1),
		(party_get_slot,':share_price',':shoen',slot_shoen_share_price),
		(store_div,':per_share_dividend',':share_price',10),
		(party_set_slot,':shoen',slot_shoen_dividend,':per_share_dividend'),
		]
	),
# script_shoen_update_share_price
('shoen_update_share_price',
	[
		(store_script_param,':shoen',1),
		(store_script_param,':transaction',2),
		(party_get_slot,':current_share_price',':shoen',slot_shoen_share_price),
		(party_get_slot,':outstanding_shares',':shoen',slot_shoen_outstanding_shares),
		(party_get_slot,':total_shares',':shoen',slot_shoen_total_shares),
		#(party_get_slot,':time_since_last_transaction',':shoen',slot_shoen_time_since_last_transaction),
		(store_sub,':purchased_shares',':total_shares',':outstanding_shares'),
		(val_mul,':purchased_shares',1000),
		(store_div,':price_ratio',':purchased_shares',':total_shares'),
		(try_begin),
			(eq,':transaction',shoen_buy_shares),
			(val_add,':price_ratio',1000),
		(else_try),
			(eq,':transaction',shoen_sell_shares),
			(store_sub,':price_ratio',1000,':price_ratio'),
		(try_end),
		(store_mul,':new_share_price',':current_share_price',':price_ratio'),
		(val_div,':new_share_price',1000),
		(assign,reg10,':current_share_price'),
		(assign,reg11,':price_ratio'),
		(assign,reg12,':new_share_price'),
		(display_message,'@current price: {reg10}, ratio: {reg11}, new price: {reg12}'),
		(party_set_slot,':shoen',slot_shoen_share_price,':new_share_price'),
		]
	),
('shoen_reset_transaction_time',
	[
		(store_script_param,':shoen',1),
		(party_set_slot,':shoen',slot_shoen_time_since_last_transaction,0),
		]
	),
('cf_troop_owns_shares_of_shoen',
	[
		(store_script_param,':troop',1),
		(store_script_param,':shoen',2),
		(assign,':troop_owns_shares',false),
		(party_get_slot,':shareholders_array',':shoen',slot_shoen_shareholders_array),
		(try_for_range,':array_index',0,num_shareholders),
			(eq,':troop_owns_shares',false),
			(call_script,'script_array_peek',':shareholders_array',':array_index'),
			(eq,'$return',':troop'),
			(assign,':troop_owns_shares',true),
		(try_end),
		(eq,':troop_owns_shares',true),
		]
	),
('cf_troop_owns_broker_shoen_shares',
	[
		(store_script_param,':broker',1),
		(store_script_param,':troop_no',2),
		(assign,':temp_array_index',0),
		(try_for_parties,':shoen'),
			(call_script,'script_cf_party_is_of_template',':shoen','pt_shoen'),
			(party_slot_eq,':shoen',slot_shoen_broker,':broker'),
			(troop_set_slot,'trp_temp_array_a',':temp_array_index',':shoen'),
			(val_add,':temp_array_index',1),
		(try_end),
		(assign,':array_length',':temp_array_index'),
		(assign,':troop_owns_broker_shares',false),
		(try_for_range,':temp_array_index',0,':array_length'),
			(eq,':troop_owns_broker_shares',false),
			(troop_get_slot,':shoen','trp_temp_array_a',':temp_array_index'),
			(call_script,'script_cf_troop_owns_shares_of_shoen',':troop_no',':shoen'),
			(assign,':troop_owns_broker_shares',true),
		(try_end),
		(eq,':troop_owns_broker_shares',true),
		]
	),
('cf_broker_has_available_investments',
	[
		(store_script_param,':broker',1),
		(assign,':temp_array_index',0),
		(try_for_parties,':shoen'),
			(call_script,'script_cf_party_is_of_template',':shoen','pt_shoen'),
			(party_slot_eq,':shoen',slot_shoen_broker,':broker'),
			(troop_set_slot,'trp_temp_array_a',':temp_array_index',':shoen'),
			(val_add,':temp_array_index',1),
		(try_end),
		(gt,':temp_array_index',0),
		]
	),
('cf_troop_is_shoen_majority_shareholder',
	[
		(store_script_param,':troop_no',1),
		(store_script_param,':shoen',2),
		(assign,':temp_array_index',0),
		(party_get_slot,':shareholders_array',':shoen',slot_shoen_shareholders_array),
		(party_get_slot,':shareholders_shares_owned_array',':shoen',slot_shoen_shareholders_shares_owned_array),
		(try_for_range,':array_index',0,num_shareholders),
			(call_script,'script_array_peek',':shareholders_array',':array_index'),
			(neq,'$return',null),
			(troop_set_slot,'trp_temp_array_a',':temp_array_index','$return'),
			(call_script,'script_array_peek',':shareholders_shares_owned_array',':array_index'),
			(troop_set_slot,'trp_temp_array_b',':temp_array_index','$return'),
			(val_add,':temp_array_index',1),
		(try_end),
		(assign,':array_length',':temp_array_index'),
		(troop_get_slot,':stored_no_of_shares','trp_temp_array_b',0),
		(try_for_range,':temp_array_index',0,':array_length'),
			(troop_get_slot,':compared_no_of_shares','trp_temp_array_b',':temp_array_index'),
			(val_max,':stored_no_of_shares',':compared_no_of_shares'),
		(try_end),
		(assign,':majority_shareholder_found',false),
		(try_for_range,':temp_array_index',0,':array_length'),
			(eq,':majority_shareholder_found',false),
			(troop_slot_eq,'trp_temp_array_b',':temp_array_index',':stored_no_of_shares'),
			(assign,':majority_shareholder_found',true),
			(troop_get_slot,':majority_shareholder','trp_temp_array_a',':temp_array_index'),
		(try_end),
		(eq,':majority_shareholder',':troop_no'),
		]
	),
('cf_shoen_get_shareholder_slot',
	[
		(store_script_param,':shoen',1),
		(store_script_param,':shareholder',2),
		(party_get_slot,':shareholders_array',':shoen',slot_shoen_shareholders_array),
		(call_script,'script_array_index_of',':shareholders_array',':shareholder'),
		(try_begin),
			(neq,'$return',null),
			(assign,reg0,'$return'),
		(else_try),
			(eq,1,0),
		(try_end),
		]
	),
('shoen_transact_shares',
	[
		(store_script_param,':shoen',1),
		(store_script_param,':transactor',2),
		(store_script_param,':transaction',3),
		(store_script_param,':no_shares',4),
		(party_get_slot,':shareholders_array',':shoen',slot_shoen_shareholders_array),
		# (party_get_slot,':outstanding_shares',':shoen',slot_shoen_outstanding_shares),
		(try_begin),
			(eq,':transaction',shoen_buy_shares),
			(try_begin),
				(call_script,'script_cf_troop_owns_shares_of_shoen',':transactor',':shoen'),
				(str_store_troop_name,s10,':transactor'),
				(display_message,'@{s10} has shares of shoen',debug_text),
				(call_script,'script_array_index_of',':shareholders_array',':transactor'),
				(assign,':shareholder_index','$return'),
				(party_get_slot,':shareholders_shares_owned_array',':shoen',slot_shoen_shareholders_shares_owned_array),
				(party_get_slot,':shareholders_dca_value_array',':shoen',slot_shoen_shareholders_dca_value_array),
				(party_get_slot,':shareholders_total_capitalization_array',':shoen',slot_shoen_shareholders_total_capitalization_array),
				(party_get_slot,':current_share_price',':shoen',slot_shoen_share_price),
				(call_script,'script_array_peek',':shareholders_shares_owned_array',':shareholder_index'),
				(assign,':num_shares_owned','$return'),
				(call_script,'script_array_peek',':shareholders_total_capitalization_array',':shareholder_index'),
				(assign,':shareholder_total_capitalization','$return'),
				(store_mul,':capitalization_delta',':no_shares',':current_share_price'),
				(val_add,':shareholder_total_capitalization',':capitalization_delta'),
				(val_add,':num_shares_owned',':no_shares'),
				(store_div,':new_dca_value',':shareholder_total_capitalization',':num_shares_owned'),
				(assign,reg10,':num_shares_owned'),
				(assign,reg11,':shareholder_total_capitalization'),
				(assign,reg12,':new_dca_value'),
				(display_message,'@No. shares: {reg10}, Total Cap: {reg11}, DCA: {reg12}',debug_text),
				(call_script,'script_array_poke',':shareholders_shares_owned_array',':shareholder_index',':num_shares_owned'),
				(call_script,'script_array_poke',':shareholders_dca_value_array',':shareholder_index',':new_dca_value'),
				(call_script,'script_array_poke',':shareholders_total_capitalization_array',':shareholder_index',':shareholder_total_capitalization'),
				(call_script,'script_object_modify_slot',obj_party,':shoen',slot_shoen_outstanding_shares,op_sub,':no_shares'),
			(else_try),
				(str_store_troop_name,s10,':transactor'),
				(display_message,'@{s10} has no shares of shoen',debug_text),
				(call_script,'script_array_push',':shareholders_array',':transactor'),
				(call_script,'script_array_index_of',':shareholders_array',':transactor'),
				(assign,':shareholder_index','$return'),
				(party_get_slot,':shareholders_shares_owned_array',':shoen',slot_shoen_shareholders_shares_owned_array),
				(party_get_slot,':shareholders_dca_value_array',':shoen',slot_shoen_shareholders_dca_value_array),
				(party_get_slot,':shareholders_total_capitalization_array',':shoen',slot_shoen_shareholders_total_capitalization_array),
				(party_get_slot,':current_share_price',':shoen',slot_shoen_share_price),
				(store_mul,':shareholder_total_capitalization',':no_shares',':current_share_price'),
				(assign,':new_dca_value',':current_share_price'),
				(assign,reg10,':no_shares'),
				(assign,reg11,':shareholder_total_capitalization'),
				(assign,reg12,':new_dca_value'),
				(display_message,'@No. shares: {reg10}, Total Cap: {reg11}, DCA: {reg12}',debug_text),
				(call_script,'script_array_poke',':shareholders_shares_owned_array',':shareholder_index',':no_shares'),
				(call_script,'script_array_poke',':shareholders_dca_value_array',':shareholder_index',':new_dca_value'),
				(call_script,'script_array_poke',':shareholders_total_capitalization_array',':shareholder_index',':shareholder_total_capitalization'),
				# (store_sub,':remaining_shares',':outstanding_shares',':no_shares'),
				(call_script,'script_object_modify_slot',obj_party,':shoen',slot_shoen_outstanding_shares,op_sub,':no_shares'),
			(try_end),
		(else_try),
			(eq,':transaction',shoen_sell_shares),
			(call_script,'script_array_index_of',':shareholders_array',':transactor'),
			(assign,':shareholder_index','$return'),
			(party_get_slot,':shareholders_shares_owned_array',':shoen',slot_shoen_shareholders_shares_owned_array),
			(party_get_slot,':shareholders_dca_value_array',':shoen',slot_shoen_shareholders_dca_value_array),
			(party_get_slot,':shareholders_total_capitalization_array',':shoen',slot_shoen_shareholders_total_capitalization_array),
			(party_get_slot,':current_share_price',':shoen',slot_shoen_share_price),
			(call_script,'script_array_peek',':shareholders_shares_owned_array',':shareholder_index'),
			(assign,':num_shares_owned','$return'),
			(assign,reg10,':num_shares_owned'),
			(display_message,'@No shares owned: {reg10}',debug_text),
			(val_sub,':num_shares_owned',':no_shares'),
			(assign,reg10,':num_shares_owned'),
			(display_message,'@No shares owned: {reg10}',debug_text),
			(val_max,':num_shares_owned',0),
			(assign,reg10,':num_shares_owned'),
			(display_message,'@No shares owned: {reg10}',debug_text),
			(try_begin),
				(eq,':num_shares_owned',0),
				(call_script,'script_object_modify_slot',obj_party,':shoen',slot_shoen_outstanding_shares,op_add,':no_shares'),
				(call_script,'script_shoen_remove_shareholder',':shoen',':transactor',':shareholder_index'),
			(else_try),
				(call_script,'script_array_peek',':shareholders_total_capitalization_array',':shareholder_index'),
				(assign,':shareholder_total_capitalization','$return'),
				(assign,reg10,':shareholder_total_capitalization'),
				(display_message,'@Cap: {reg10}',debug_text),
				(store_mul,':capitalization_delta',':no_shares',':current_share_price'),
				(assign,reg10,':capitalization_delta'),
				(display_message,'@Cap delta: {reg10}',debug_text),
				(val_sub,':shareholder_total_capitalization',':capitalization_delta'),
				(assign,reg10,':shareholder_total_capitalization'),
				(display_message,'@New Cap: {reg10}',debug_text),
				(store_div,':new_dca_value',':shareholder_total_capitalization',':num_shares_owned'),
				(assign,reg10,':num_shares_owned'),
				(display_message,'@No shares owned: {reg10}',debug_text),
				(assign,reg10,':no_shares'),
				(assign,reg11,':shareholder_total_capitalization'),
				(assign,reg12,':new_dca_value'),
				(display_message,'@No. shares: {reg10}, Total Cap: {reg11}, DCA: {reg12}',debug_text),
				(call_script,'script_array_poke',':shareholders_shares_owned_array',':shareholder_index',':num_shares_owned'),
				(call_script,'script_array_poke',':shareholders_dca_value_array',':shareholder_index',':new_dca_value'),
				(call_script,'script_array_poke',':shareholders_total_capitalization_array',':shareholder_index',':shareholder_total_capitalization'),
				(call_script,'script_object_modify_slot',obj_party,':shoen',slot_shoen_outstanding_shares,op_add,':no_shares'),
			(try_end),
		(try_end),
		(call_script,'script_shoen_update_share_price',':shoen',':transaction'),
		]
	),
('shoen_remove_shareholder',
	[
		(store_script_param,':shoen',1),
		(store_script_param,':transactor',2),
		(store_script_param,':shareholder_index',3),
		(party_get_slot,':shareholders_array',':shoen',slot_shoen_shareholders_array),
		(party_get_slot,':shareholders_accumulated_dividends_array',':shoen',slot_shoen_shareholders_accumulated_dividends_array),
		(party_get_slot,':shareholders_shares_owned_array',':shoen',slot_shoen_shareholders_shares_owned_array),
		(party_get_slot,':shareholders_dca_value_array',':shoen',slot_shoen_shareholders_dca_value_array),
		(party_get_slot,':shareholders_total_capitalization_array',':shoen',slot_shoen_shareholders_total_capitalization_array),
		(call_script,'script_array_peek',':shareholders_accumulated_dividends_array',':shareholder_index'),
		(try_begin),
			(gt,'$return',0),
			(assign,reg10,'$return'),
			(try_begin),
				(eq,':transactor','trp_player'),
				(display_message,'@Your accumulated dividends amount to {reg10} mon'),
			(try_end),
			(troop_add_gold,':transactor',reg10),
		(try_end),
		(call_script,'script_array_poke',':shareholders_array',':shareholder_index',null),
		(call_script,'script_array_poke',':shareholders_accumulated_dividends_array',':shareholder_index',0),
		(call_script,'script_array_poke',':shareholders_shares_owned_array',':shareholder_index',0),
		(call_script,'script_array_poke',':shareholders_dca_value_array',':shareholder_index',0),
		(call_script,'script_array_poke',':shareholders_total_capitalization_array',':shareholder_index',0),
		(try_for_range,':array_index',0,250),
			(call_script,'script_array_peek',':shareholders_array',':array_index'),
			(eq,'$return',null),
			(call_script,'script_array_swap_right',':shareholders_array',':array_index'),
			(call_script,'script_array_swap_right',':shareholders_accumulated_dividends_array',':array_index'),
			(call_script,'script_array_swap_right',':shareholders_shares_owned_array',':array_index'),
			(call_script,'script_array_swap_right',':shareholders_dca_value_array',':array_index'),
			(call_script,'script_array_swap_right',':shareholders_total_capitalization_array',':array_index'),
		(try_end),
		]
	),
('cf_shoen_ai_buy_shares',
	[
		(store_script_param,':ai_troop',1),
		(store_troop_gold,':troop_wealth',':ai_troop'),
		(assign,':temp_array_index',0),
		(try_for_parties,':shoen'),
			(call_script,'script_cf_party_is_of_template',':shoen','pt_shoen'),
			(party_get_slot,':share_price_moving_avg',':shoen',slot_shoen_share_price_moving_avg),
			(party_get_slot,':share_price',':shoen',slot_shoen_share_price),
			(try_begin),
				(lt,':share_price',':share_price_moving_avg'),
				(troop_set_slot,'trp_temp_array_a',':temp_array_index',':shoen'),
				(val_add,':temp_array_index',1),
			(try_end),
		(try_end),
		(store_random_in_range,':shoen_index',0,':temp_array_index'),
		(troop_get_slot,':shoen','trp_temp_array_a',':shoen_index'),
		(party_get_slot,':shoen_outstanding_shares',':shoen',slot_shoen_outstanding_shares),
		(party_get_slot,':current_share_price',':shoen',slot_shoen_share_price),
		(gt,':shoen_outstanding_shares',0),
		(store_random_in_range,':no_shares_to_buy',1,6),
		(val_mul,':no_shares_to_buy',10),
		(store_mul,':total_purchase_price',':current_share_price',':no_shares_to_buy'),
		(gt,':troop_wealth',':total_purchase_price'),
		(call_script,'script_shoen_transact_shares',':shoen',':ai_troop',shoen_buy_shares,':no_shares_to_buy'),
		(call_script,'script_shoen_reset_transaction_time',':shoen'),
		(party_get_slot,':shoen_town',':shoen',slot_shoen_town),
		(str_store_party_name,10,':shoen_town'),
		(str_store_troop_name,s11,':ai_troop'),
		(display_message,'@{s11} has bought shares in {s10} shoen',debug_text),
		(troop_remove_gold,':ai_troop',':total_purchase_price'),
		(call_script,'script_modify_troop_wealth',':ai_troop'),
		]
	),
('cf_shoen_ai_sell_shares',
	[
		(store_script_param,':ai_troop',1),
		(store_random_in_range,':npc_looking',0,3),
		(eq,':npc_looking',0),
		(assign,':temp_array_index',0),
		(try_for_parties,':shoen'),
			(call_script,'script_cf_party_is_of_template',':shoen','pt_shoen'),
			(party_get_slot,':share_price_moving_avg',':shoen',slot_shoen_share_price_moving_avg),
			(party_get_slot,':share_price',':shoen',slot_shoen_share_price),
			(try_begin),
				(gt,':share_price',':share_price_moving_avg'),
				(call_script,'script_cf_troop_owns_shares_of_shoen',':ai_troop',':shoen'),
				(troop_set_slot,'trp_temp_array_a',':temp_array_index',':shoen'),
				(val_add,':temp_array_index',1),
			(try_end),
		(try_end),
		(store_random_in_range,':shoen_index',0,':temp_array_index'),
		(troop_get_slot,':shoen','trp_temp_array_a',':shoen_index'),
		(call_script,'script_cf_shoen_get_shareholder_slot',':shoen',':ai_troop'),
		(neq,reg0,null),
		(assign,':shareholder_index',reg0),
		(party_get_slot,':shareholder_shares_owned_array',':shoen',slot_shoen_shareholders_shares_owned_array),
		(party_get_slot,':shareholder_dca_value_array',':shoen',slot_shoen_shareholders_dca_value_array),
		(party_get_slot,':current_share_price',':shoen',slot_shoen_share_price),
		(call_script,'script_array_peek',':shareholder_shares_owned_array',':shareholder_index'),
		(assign,':num_shares_owned','$return'),
		(call_script,'script_array_peek',':shareholder_dca_value_array',':shareholder_index'),
		(assign,':current_dca_value','$return'),
		(gt,':current_share_price',':current_dca_value'),
		(call_script,'script_shoen_get_num_shares_to_sell',':num_shares_owned'),
		(assign,':no_shares_to_sell',reg0),
		(store_mul,':total_gains',':current_share_price',':no_shares_to_sell'),
		(call_script,'script_shoen_transact_shares',':shoen',':ai_troop',shoen_sell_shares,':no_shares_to_sell'),
		(call_script,'script_shoen_reset_transaction_time',':shoen'),
		(party_get_slot,':shoen_town',':shoen',slot_shoen_town),
		(str_store_party_name,10,':shoen_town'),
		(str_store_troop_name,11,':ai_troop'),
		(display_message,'@An ai has sold shares in {s10} shoen'),
		(troop_add_gold,':ai_troop',':total_gains'),
		(call_script,'script_modify_troop_wealth',':ai_troop'),
		]
	),
('shoen_get_num_shares_to_sell',
	[
		(store_script_param,':num_shares_owned',1),
		(store_div,':max_shares',':num_shares_owned',10),
		(val_add,':max_shares',1),
		(store_random_in_range,':no_shares_to_sell',1,':max_shares'),
		(val_mul,':no_shares_to_sell',10),
		(assign,reg0,':no_shares_to_sell'),	
		]
	),
      ###################################################################################################
      #################################### Array functions #####################################################
      ###################################################################################################
("array_initialize",
	[
		(store_script_param,":array_length",1),
		(store_random_in_range,reg1,cities_begin,cities_end),
		(set_spawn_radius,20),
		(spawn_around_party,reg1,'pt_array'),
		(party_set_slot,reg0,array_value_length,':array_length'),
		(call_script,'script_array_clear',reg0),
		]
	),
('array_clear',
        [
          (store_script_param,':input_array',1),
          (party_get_slot,':array_length',':input_array',array_value_length),
          (try_for_range,reg1,0,':array_length'),
            (party_set_slot,':input_array',reg1,null),
          (try_end),
          (party_set_slot,':input_array',array_value_high_index,0),
          (assign,'$return',':input_array'),
      ]),
('array_copy',
        [
          (store_script_param,':input_array',1),
          (party_get_slot,':length',':input_array',array_value_length),
          (call_script,'script_array_initialize',':length'),
          (assign,':copy_of_input_array','$return'),
          (try_for_range,':i',0,':length'),
            (party_get_slot,':value',':input_array',':i'),
            (party_set_slot,':copy_of_input_array',':i',':value'),
          (try_end),
          (assign,'$return',':copy_of_input_array'),
      ]),
('array_copy_to_temp',
		[
			(store_script_param,':temp_dest_array',1),
			(store_script_param,':source_array',2),
			(try_for_range,':index',0,250),
				(call_script,'script_array_peek',':source_array',':index'),
				(troop_set_slot,':temp_dest_array',':index','$return'),
			(try_end),
			]
		),
('array_copy_from_temp',
		[
			(store_script_param,':dest_array',1),
			(store_script_param,':temp_source_array',2),
			(try_for_range,':index',0,250),
				(troop_get_slot,':value',':temp_source_array',':index'),
				(call_script,'script_array_poke',':dest_array',':index',':value'),
			(try_end),
			]
		),
('array_modify_value',
	[
		(store_script_param,':array',1),
		(store_script_param,':array_index',2),
		(store_script_param,':op_code',3),
		(store_script_param,':value',4),
		(call_script,'script_object_modify_slot',obj_party,':array',':array_index',':op_code',':value'),
		]
	),
('array_push',
        [
          (store_script_param,':input_array',1),
          (store_script_param,':input_value',2),
          (party_get_slot,':high_index',':input_array',array_value_high_index),
		  (val_clamp,':high_index',0,250),
          (party_set_slot,':input_array',':high_index',':input_value'),
          (val_add,':high_index',1),
          (party_set_slot,':input_array',array_value_high_index,':high_index'),
          (party_set_slot,':input_array',array_value_last_pushed,':input_value'),
      ]),
('array_pop',
        [
          (store_script_param,':input_array',1),
          (party_get_slot,':high_index',':input_array',array_value_high_index),
		  (val_sub,':high_index',1),
          (party_get_slot,':return_value',':input_array',':high_index'),
          (party_set_slot,':input_array',':high_index',array_value_null),
          (party_set_slot,':input_array',array_value_last_popped,':return_value'),
          (party_set_slot,':input_array',array_value_high_index,':high_index'),
          (assign,'$return',':return_value'),
      ]),
('array_remove_index',
        [
          (store_script_param,':input_array',1),
          (store_script_param,':index',2),
          (party_set_slot,':input_array',':index',array_value_null),
          (party_get_slot,':length',':input_array',array_value_length),
          (val_add,':index',1),
          (try_for_range,':i',':index',':length'),
            (party_get_slot,':value',':input_array',':i'),
            (store_sub,':j',':i',1),
            (party_set_slot,':input_array',':j',':value'),
          (try_end),
          (party_set_slot,':input_array',':length',array_value_null),
          (party_get_slot,':high_index',':input_array',array_value_high_index),
          (val_sub,':high_index',1),
          (party_set_slot,':input_array',array_value_high_index,':high_index'),
      ]),
('array_peek',
        [
          (store_script_param,':input_array',1),
          (store_script_param,':input_index',2),
          (party_get_slot,':return_value',':input_array',':input_index'),
          (assign,'$return',':return_value'),
      ]),
('array_poke',
        [
          (store_script_param,':input_array',1),
          (store_script_param,':input_index',2),
		  (store_script_param,':input_value',3),
		  (val_clamp,':input_index',0,250),
          (party_set_slot,':input_array',':input_index',':input_value'),
      ]),
('array_queue',
        [
          (store_script_param,':input_array',1),
          (party_get_slot,'$return',':input_array',0),
          (party_set_slot,':input_array',array_value_last_queued,'$return'),
          (call_script,'script_array_shift_left',':input_array',0),
      ]),
('array_cycle',
        [
          (store_script_param,':input_array',1),
          (call_script,'script_array_queue',':input_array'),
          (call_script,'script_array_push',':input_array','$return'),
      ]),
('array_shift_left',
        [
          (store_script_param,':input_array',1),
          (store_script_param,':init_index',2),
          (party_get_slot,':array_length',':input_array',array_value_high_index),
          (try_for_range,':i',':init_index',':array_length'),
            (store_add,':j',':i',1),
            (party_get_slot,':value',':input_array',':j'),
            (party_set_slot,':input_array',':i',':value'),
          (try_end),
		  (val_sub,':array_length',1),
          (party_set_slot,':input_array',':array_length',array_value_null),
          (party_set_slot,':input_array',array_value_high_index,':array_length'),
      ]),
('array_add_to_array',
		[
			(store_script_param,':dest_array',1),
			(store_script_param,':source_array',2),
			(try_for_range,':array_index',0,250),
				(call_script,'script_array_peek',':source_array',':array_index'),
				(assign,':source_addend','$return'),
				(call_script,'script_array_peek',':dest_array',':array_index'),
				(assign,':dest_addend','$return'),
				(val_add,':dest_addend',':source_addend'),
				(call_script,'script_array_poke',':dest_array',':array_index',':dest_addend'),
			(try_end),
			]
		),
				
('array_swap_right',
	[
		(store_script_param,':array',1),
		(store_script_param,':index',2),
		(store_add,':index_right',':index',1),
		(try_begin),
			(gt,':index_right',249),
			(assign,':index_right',':index'),
		(try_end),
		(call_script,'script_array_peek',':array',':index'),
		(assign,':left_value','$return'),
		(call_script,'script_array_peek',':array',':index_right'),
		(assign,':right_value','$return'),
		(call_script,'script_array_poke',':array',':index',':right_value'),
		(call_script,'script_array_poke',':array',':index_right',':left_value'),
		]
	),
('array_swap_left',
	[
		(store_script_param,':array',1),
		(store_script_param,':index',2),
		(store_sub,':index_left',':index',1),
		(try_begin),
			(lt,':index_left',0),
			(assign,':index_left',':index'),
		(try_end),
		(call_script,'script_array_peek',':array',':index'),
		(assign,':right_value','$return'),
		(call_script,'script_array_peek',':array',':index_left'),
		(assign,':left_value','$return'),
		(call_script,'script_array_poke',':array',':index_left',':right_value'),
		(call_script,'script_array_poke',':array',':index',':left_value'),
		]
	),
('array_index_eq',
	[
		(store_script_param,':array',1),
		(store_script_param,':array_index',2),
		(store_script_param,':test_value',3),
		(assign,'$return',false),
		(try_begin),
			(val_add,':array_index',5),
			(party_slot_eq,':array',':array_index',':test_value'),
			(assign,'$return',true),
		(try_end),
		]
	),
('array_index_ge',
	[
		(store_script_param,':array',1),
		(store_script_param,':array_index',2),
		(store_script_param,':test_value',3),
		(assign,'$return',false),
		(try_begin),
			(val_add,':array_index',5),
			(party_slot_ge,':array',':array_index',':test_value'),
			(assign,'$return',true),
		(try_end),
		]
	),
('array_index_of',
	[
		(store_script_param,':input_array',1),
		(store_script_param,':input_value',2),
		(party_get_slot,':high_index',':input_array',array_value_high_index),
		(assign,':index_found',false),
		(try_for_range,':index',0,':high_index'),
			(eq,':index_found',false),
			(party_slot_eq,':input_array',':index',':input_value'),
			(assign,':index_found',true),
			(assign,':return_index',':index'),
		(try_end),
		(try_begin),
			(eq,':index_found',true),
			(assign,'$return',':return_index'),
		(else_try),
			(assign,'$return',null),
		(try_end),
		]
	),
      ('array_remove_if_ge',
        [
          (store_script_param_1,':input_array'),
          (store_script_param_2,':test_value'),
          (party_get_slot,':high_index',':input_array',array_value_high_index),
          (try_for_range,':index',5,':high_index'),
            (party_get_slot,':array_value',':input_array',':index'),
            (ge,':array_value',':test_value'),
            (party_set_slot,':input_array',':index',array_value_null),
          (try_end),
      ]),
      ###################################################################################################
      #################################### Faction AI functions ##################################################
      ###################################################################################################
      #script modify faction attitude
      ("modify_faction_attitude",
        [
          (store_script_param_1,':input_faction'),
          #(call_script,'script_debug_relations_and_attitude',),
          (store_relation,':relation',':input_faction',"fac_player_faction"),
          (try_begin),
            (lt,':relation',-50),
            (assign,':attitude',att_hostile),
          (else_try),
            (is_between,':relation',-50,-25),
            (assign,':attitude',att_offensive),
          (else_try),
            (is_between,':relation',-25,-10),
            (assign,':attitude',att_defensive),
          (else_try),
            (is_between,':relation',-10,-3),
            (assign,':attitude',att_secretive),
          (else_try),
            (is_between,':relation',-3,3),
            (assign,':attitude',att_cautious),
          (else_try),
            (is_between,':relation',3,10),
            (assign,':attitude',att_friendly),
          (else_try),
            (ge,':relation',10),
            (assign,':attitude',att_generous),
          (try_end),
          (faction_set_slot,':input_faction',slot_faction_att_to_player,':attitude'),
          #(call_script,'script_debug_relations_and_attitude',hidaka),
      ]),
      
      #script modify troop attitudes
      ("modify_troop_attitude",
        [
          (store_script_param_1,':input_troop'),
          (store_troop_faction,':faction',':input_troop'),
          (faction_get_slot,':attitude',':faction',slot_faction_att_to_player),
          (troop_set_slot,':input_troop',slot_troop_att_to_player,':attitude'),
      ]),
      
      #script modify town attitudes
      ("modify_town_attitude",
        [
          (store_script_param_1,':input_town'),
          #(call_script,'script_debug_relations_and_attitude',hidaka),
          (store_faction_of_party,':faction',':input_town'),
          (faction_get_slot,':attitude',':faction',slot_faction_att_to_player),
          (party_get_slot,':town_fame',':input_town',slot_town_player_relation),
          (try_begin),
            (ge,':town_fame',25),
            (assign,':town_att',att_generous),
          (else_try),
            (is_between,':town_fame',10,25),
            (assign,':town_att',att_friendly),
          (else_try),
            (is_between,':town_fame',0,10),
            (assign,':town_att',att_cautious),
          (else_try),
            (is_between,':town_fame',-10,0),
            (assign,':town_att',att_secretive),
          (else_try),
            (is_between,':town_fame',-20,-10),
            (assign,':town_att',att_defensive),
          (else_try),
            (is_between,':town_fame',-50,-20),
            (assign,':town_att',att_offensive),
          (else_try),
            (lt,':town_fame',-50),
            (assign,':town_att',att_hostile),
          (try_end),
          (val_add,':attitude',':town_att'),
          (val_div,':attitude',2),
		  (store_add,':upper_limit',att_generous,1),
		  (val_clamp,':attitude',att_hostile,':upper_limit'),
          (party_set_slot,':input_town',slot_town_att_to_player,':attitude'),
          #(call_script,'script_debug_relations_and_attitude',hidaka),
      ]),
      
      #script update patrol attitude
      ("update_patrol_attitude",
        [
          (store_script_param_1,':patrol'),
          (store_script_param_2,':origin'),
          #(call_script,'script_debug_relations_and_attitude',hidaka),
          (store_faction_of_party,':faction',':patrol'),
          (party_get_slot,':town_att',':origin',slot_town_att_to_player),
          (faction_get_slot,':fac_att',':faction',slot_faction_att_to_player),
          (party_get_template_id,':template',':patrol'),
          (try_begin),
            (eq,':template',"pt_local_patrol"),
            (store_mul,':attitude',':town_att',3),
            (val_add,':attitude',':fac_att'),
            (val_div,':attitude',4),
          (else_try),
            (this_or_next|eq,':template',"pt_hosokawa_allied_patrol"),
            (eq,':template',"pt_yamana_allied_patrol"),
            (store_mul,':attitude',':fac_att',3),
            (val_add,':attitude',':town_att'),
            (val_div,':attitude',4),
          (else_try),
            (this_or_next|eq,':template','pt_hosokawa_patrol'),
            (eq,':template','pt_yamana_patrol'),
            (store_mul,':attitude',':fac_att',1),
          (try_end),
          (try_begin),
            (lt,':attitude',att_hostile),
            (assign,':attitude',att_hostile),
          (else_try),
            (gt,':attitude',att_generous),
            (assign,':attitude',att_generous),
          (try_end),
          (party_set_slot,':patrol',slot_spawn_att_to_player,':attitude'),
          #(call_script,'script_debug_relations_and_attitude',hidaka),
      ]),
	  ('count_faction_forts',
		[
			(display_message,'@This is script CountFactionForts'),
			]
		),
('faction_strength',
	[
		(store_script_param,':faction',1),
		(store_script_param,':opt',2),
		(try_begin),
			(eq,':opt',0),
            (assign,':num_cities',0),
            (assign,':num_towns',0),
            (assign,':num_villages',0),
            (assign,':num_forts',0),
            (assign,':num_parties',0),
            (assign,':num_allies',0),
            (try_for_range,':city',cities_begin,cities_end), # count all cities allied to :faction
				(store_faction_of_party,':fac',':city'),
				(call_script,'script_cf_faction_is_ally_of_faction',':faction',':fac'),
				(val_add,':num_cities',1),
            (try_end),
            (try_for_range,':town',towns_begin,towns_end), # count all towns allied to :faction
				(store_faction_of_party,':fac',':town'),
				(call_script,'script_cf_faction_is_ally_of_faction',':faction',':fac'),
				(val_add,':num_towns',1),
            (try_end),
            (try_for_range,':village',villages_begin,villages_end), # count all villages allied to :faction
				(store_faction_of_party,':fac',':village'),
				(call_script,'script_cf_faction_is_ally_of_faction',':faction',':fac'),
				(val_add,':num_villages',1),
            (try_end),
            (try_for_parties,':fort'), # count all forts belonging to :faction
				(call_script,'script_cf_party_is_of_template',':fort','pt_fort'),
				(store_faction_of_party,':fac',':fort'),
				(call_script,'script_cf_faction_is_ally_of_faction',':faction',':fac'),
				(val_add,':num_forts',1),
            (try_end),
            (try_for_parties,':party'), # count all parties belonging to or allied to :faction
				(store_faction_of_party,':fac',':party'),
				(call_script,'script_cf_faction_is_ally_of_faction',':faction',':fac'),
				(val_add,':num_parties',1),
            (try_end),
            (try_for_range,':fac','fac_hosokawa','fac_end_fac'), # count all allies of :faction
				(call_script,'script_cf_faction_is_ally_of_faction',':faction',':fac'),
				(val_add,':num_allies',1),
            (try_end),
            # values: allies are worth 100, cities 50, towns 25, villages 10, forts 15, parties 2
            # sum all
            (val_mul,':num_allies',100),
            (val_mul,':num_cities',50),
            (val_mul,':num_towns',25),
            (val_mul,':num_villages',10),
            (val_mul,':num_forts',15),
            (val_mul,':num_parties',2),
            (store_add,':sum',':num_allies',':num_cities'),
            (val_add,':sum',':num_towns'),
            (val_add,':sum',':num_villages'),
            (val_add,':sum',':num_forts'),
            (val_add,':sum',':num_parties'),
            # normalization formula: score = 1000 + (raw-avg)*1000/avg, avg = (raw+1000)/2
            (store_add,':avg',':sum',1000),
            (val_div,':avg',2),
            (store_add,':diff',':sum',':avg'),
            (val_mul,':diff',1000),
            (val_div,':diff',':avg'),
            (store_add,':faction_str',1000,':diff'),
			(val_clamp,':faction_str',0,9999),
            (faction_set_slot,':faction',slot_faction_strength,':faction_str'),
            # (str_store_faction_name,21,':faction'),
            # (assign,reg21,':faction_str'),
            # (display_message,'str_fac_str'),
		(try_end),
        ]
	),
('faction_ai_decisor',
	[
		(store_script_param_1,':faction'),
		(faction_get_slot,':score',':faction',slot_faction_strength),
		(faction_get_slot,':intel',':faction',slot_faction_intel), # most recent intelligence of enemy faction strength
		(faction_get_slot,':fac_flags',':faction',slot_faction_possession_flags), # flags corresponding to whether allies, towns, etc have changed from the start of the game
		(store_div,':intel_date',':intel',10000), # gets the day number of the most recent intel (strength is a four digit number, so this works well. Yeah integer math!)
		(store_mul,':date_addend',':intel_date',10000),
		(store_sub,':enemy_score',':intel',':date_addend'),
		(store_current_day,':date'),
		(store_sub,':date_diff',':date',':intel_date'),
		(store_sub,':score_diff',':score',':enemy_score'),
		(val_abs,':score_diff'),
		(assign,':score_diff','$return'),
		(try_begin), # here begineth the logic
			(gt,':date_diff',5),
			(assign,':mission_opt',mission_intel),
			(str_store_faction_name,s10,':faction'),
			(display_message,'@{s10} will mount an intelligence mission',debug_text),
		(else_try),
            (try_begin),
				(lt,':score_diff',100),
				(assign,':mission_opt',mission_do_nothing),
				(str_store_faction_name,s10,':faction'),
				(display_message,'@{s10} will do nothing',debug_text),
            (else_try),
				# (try_begin),
					# (call_script,'script_get_flag_bit',':fac_flags',4),
					# (eq,reg0,1),
					# (assign,':mission_opt',mission_diplomacy),
					# (str_store_faction_name,s10,':faction'),
					# (display_message,'@{s10} will mount a diplomatic mission',debug_text),
				# (else_try),
					# (call_script,'script_get_flag_bit',':fac_flags',3),
					# (eq,reg0,1),
					# (assign,':mission_opt',mission_army_capture),
					# (str_store_faction_name,s10,':faction'),
					# (display_message,'@{s10} will mount a defensive city capture mission',debug_text),
				# (else_try),
					# (call_script,'script_get_flag_bit',':fac_flags',2),
					# (eq,reg0,1),
					# (assign,':mission_opt',mission_war_party_capture),
					# (str_store_faction_name,s10,':faction'),
					# (display_message,'@{s10} will mount a defensive town capture mission',debug_text),
				# (else_try),
					# (call_script,'script_get_flag_bit',':fac_flags',1),
					# (eq,reg0,1),
					# (assign,':mission_opt',mission_raiders_capture),
					# (str_store_faction_name,s10,':faction'),
					# (display_message,'@{s10} will mount a defensive village capture mission',debug_text),
				# (else_try),
					# (call_script,'script_count_faction_forts',':faction'),
					# (lt,'$return','$g_max_faction_forts'),
					# (assign,':mission_opt',mission_build_fort),
					# (str_store_faction_name,s10,':faction'),
					# (display_message,'@{s10} will build a fort',debug_text),
				# (else_try),
					(assign,':mission_opt',mission_do_nothing),
					(str_store_faction_name,s10,':faction'),
					(display_message,'@{s10} will do nothing',debug_text),
				# (try_end),
            (try_end),
		(try_end),
		(assign,reg0,':mission_opt'),
        ]
	),
('faction_ai_mission',
	[
		(store_script_param_1,':faction'),
		(store_script_param_2,':mission_opt'),
		(try_begin),
            (eq,':mission_opt',mission_do_nothing), # intially take no action
            (store_random_in_range,reg1,0,100), # the random chance part
            (try_begin),
				(is_between,reg1,0,60), # take no action
				(display_message,'@{s10} will still do nothing',debug_text),
            (else_try),
				(is_between,reg1,60,85),
				(assign,':mission_opt',mission_raiders_raid),
				(display_message,'@{s10} will mount raid',debug_text),
				# (call_script,'script_faction_ai_mission',':faction',':mission_opt'),
            (else_try),
				(is_between,reg1,85,95),
				(assign,':mission_opt',mission_build_fort),
				(display_message,'@{s10} will build a fort',debug_text),
				# (call_script,'script_faction_ai_mission',':faction',':mission_opt'),
            (else_try),
				(is_between,reg1,95,98),
				(assign,':mission_opt',mission_raiders_capture), # offenive
				(display_message,'@{s10} will attempt to capture a village',debug_text),
				#(call_script,'script_faction_ai_mission2',':faction',':mission_opt'), # write script_faction_ai_mission2, offensive actions
            (else_try),
				(eq,reg1,98),
				(assign,':mission_opt',mission_war_party_capture),
				(display_message,'@{s10} will attempt to capture a town',debug_text),
				#(call_script,'script_faction_ai_mission2',':faction',':mission_opt'),
            (else_try),
				(eq,reg1,99),
				(assign,':mission_opt',mission_army_capture),
				(display_message,'@{s10} will attempt to capture a city',debug_text),
				#(call_script,'script_faction_ai_mission2',':faction',':mission_opt'),
            (try_end),
		(else_try),
            (eq,':mission_opt',mission_build_fort),
			(faction_get_slot,':fac',':faction',slot_faction_enemy_faction),
            (call_script,'script_select_random_faction_city',':fac'),
            (assign,':dest','$return'), # assign the return value of random faction city as the fort build destination
            (call_script,'script_select_random_faction_city',':faction'),
            (assign,':origin','$return'), # assign the builder start from the return value
            (party_template_get_slot,':spawn_cost','pt_builder',slot_template_spawn_cost), # need new slot def for cost to factions of spawning, roll out to other templates
            (faction_slot_ge,':faction',slot_faction_spawn_points,':spawn_cost'),
            (call_script,'script_object_modify_slot',obj_faction,':faction',slot_faction_spawn_points,op_sub,':spawn_cost'),
            (set_spawn_radius,0),
            (spawn_around_party,':origin','pt_builder'),
            (try_begin),
				(eq,':faction','fac_hosokawa'),
				(store_random_in_range,':count',8,12),
				(party_add_members,reg0,'trp_t2_light_cav_h',':count'),
				(party_add_members,reg0,'trp_t2_spear_samurai_h',':count'),
				(val_add,':count',7),
				(party_add_members,reg0,'trp_t3_bow_ashigaru_h',':count'),
				(party_add_members,reg0,'trp_t2_spear_ashigaru_h',':count'),
            (else_try),
				(store_random_in_range,':count',8,12),
				(party_add_members,reg0,'trp_t2_light_cav_y',':count'),
				(party_add_members,reg0,'trp_t2_spear_samurai_y',':count'),
				(val_add,':count',7),
				(party_add_members,reg0,'trp_t3_bow_ashigaru_y',':count'),
				(party_add_members,reg0,'trp_t2_spear_ashigaru_y',':count'),
            (try_end),
            (party_set_ai_behavior,reg0,ai_bhvr_travel_to_party),
            (party_set_ai_object,reg0,':dest'),
            (faction_get_slot,':attitude',':faction',slot_faction_att_to_player),
            (party_set_slot,reg0,slot_spawn_att_to_player,':attitude'),
		(else_try),
            (eq,':mission_opt',mission_diplomacy),
            (try_begin),
				(eq,':faction','fac_hosokawa'),
				(assign,':template','pt_hosokawa_kuge'),
            (else_try),
				(assign,':template','pt_yamana_kuge'),
            (try_end),
            (party_template_get_slot,':spawn_cost',':template',slot_template_spawn_cost),
            (faction_slot_ge,':faction',slot_faction_spawn_points,':spawn_cost'),
            (call_script,'script_object_modify_slot',obj_faction,':faction',slot_faction_spawn_points,op_sub,':spawn_cost'),
            (try_begin), # determine which ally (allies) are no longer allied to :faction, need to reorder factions in the list to get the on-aligned factions at the top of the list
				(eq,':faction','fac_hosokawa'),
				(try_for_range,':ally','fac_hosokawa','fac_yamana'),
					(faction_slot_eq,':ally',slot_faction_hosokawa_ally,0),
					(assign,':target_faction',':ally'),
					(assign,':ally','fac_end_fac'), # should break out of the loop
				(try_end),
            (else_try),
				(eq,':faction','fac_yamana'),
				(try_for_range,':ally','fac_yamana','fac_end_fac'),
					(faction_slot_eq,':ally',slot_faction_yamana_ally,0),
					(assign,':target_faction',':ally'),
					(assign,':ally','fac_end_fac'), # should break out of the loop
				(try_end),
            (try_end),
            (call_script,'script_select_random_faction_town',':faction'),
            (assign,':origin','$return'),
            (call_script,'script_select_random_faction_town',':target_faction'),
            (assign,':dest','$return'),
            (set_spawn_radius,0),
            (spawn_around_party,':origin',':template'),
            (assign,':diplomat',reg0),
            (try_begin),
				(eq,':faction','fac_hosokawa'),
				(assign,':template','pt_hosokawa_patrol'),
            (else_try),
				(assign,':template','pt_hosokawa_patrol'),
            (try_end),
            (party_add_template,':diplomat',':template'), # reinforce kuge retinue with extra troops
            (party_set_ai_behavior,':diplomat',ai_bhvr_travel_to_party),
            (party_set_ai_object,':diplomat',':dest'),
            (party_set_slot,':diplomat',slot_spawn_origin,':origin'),
            (party_set_slot,':diplomat',slot_spawn_dest,':dest'),
            (faction_get_slot,':attitude',':faction',slot_faction_att_to_player),
            (party_set_slot,':diplomat',slot_spawn_att_to_player,':attitude'),
		(else_try),
            (eq,':mission_opt',mission_army_capture),
            (assign,':template','pt_army'),
            (party_template_get_slot,':spawn_cost',':template',slot_template_spawn_cost),
            (faction_slot_ge,':faction',slot_faction_spawn_points,':spawn_cost'),
            (call_script,'script_object_modify_slot',obj_faction,':faction',slot_faction_spawn_points,op_sub,':spawn_cost'),
            (try_begin), # determine which cities need attacking
				(eq,':faction','fac_hosokawa'),
				(try_for_range,':city','p_city_5','p_city_11'),
					(party_get_slot,':fac',':city',slot_town_initial_faction), # compare current city faction against original order in module_parties
					(store_faction_of_party,':fac2',':city'),
					(neq,':fac',':fac2'),
					(assign,':dest',':city'),
					(assign,':city','p_city_11'), # should break out of the loop
				(try_end),
            (else_try),
				(eq,':faction','fac_yamana'),
				(try_for_range,':city','p_city_11','p_town_1'),
					(party_get_slot,':fac',':city',slot_town_initial_faction), # compare current city faction against original order in module_parties
					(store_faction_of_party,':fac2',':city'),
					(neq,':fac',':fac2'),
					(assign,':dest',':city'),
					(assign,':city','p_town_1'), # should break out of the loop
				(try_end),
            (try_end),
            (call_script,'script_select_random_faction_city',':faction'),
            (assign,':origin','$return'),
            (set_spawn_radius,0),
            (spawn_around_party,':origin',':template'),
			(assign,':army',reg0),
			(call_script,'script_faction_add_faction_reinforcements',':army',':faction'),
            (party_set_faction,':army',':faction'),
            (party_set_ai_behavior,':army',ai_bhvr_attack_party),
            (party_set_ai_object,':army',':dest'),
            (faction_get_slot,':attitude',':faction',slot_faction_att_to_player),
            (party_set_slot,':army',slot_spawn_att_to_player,':attitude'),
            (party_set_slot,':army',slot_spawn_origin,':origin'),
            (party_set_slot,':army',slot_spawn_dest,':dest'),
            (party_set_slot,':army',slot_spawn_orders,orders_capture),
            (party_set_slot,':dest',slot_town_siege_attacker,':army'),
		(else_try),
            (eq,':mission_opt',mission_war_party_capture),
            (try_begin),
				(eq,':faction','fac_hosokawa'),
				(assign,':template','pt_hosokawa_war_party'),
            (else_try),
				(assign,':template','pt_yamana_war_party'),
            (try_end),
            (party_template_get_slot,':spawn_cost',':template',slot_template_spawn_cost),
            (faction_slot_ge,':faction',slot_faction_spawn_points,':spawn_cost'),
            (call_script,'script_object_modify_slot',obj_faction,':faction',slot_faction_spawn_points,op_sub,':spawn_cost'),
            (try_begin), # determine which cities need attacking
				(eq,':faction','fac_hosokawa'),
				(try_for_range,':town','p_town_1','p_town_11'),
					(party_get_slot,':fac',':town',slot_town_initial_faction), # compare current city faction against original order in module_parties
					(store_faction_of_party,':fac2',':town'),
					(neq,':fac',':fac2'),
					(assign,':dest',':city'),
					(assign,':town','p_town_11'), # should break out of the loop
				(try_end),
            (else_try),
				(eq,':faction','fac_yamana'),
				(try_for_range,':town','p_town_11','p_village_1'),
					(party_get_slot,':fac',':town',slot_town_initial_faction), # compare current city faction against original order in module_parties
					(store_faction_of_party,':fac2',':town'),
					(neq,':fac',':fac2'),
					(assign,':dest',':town'),
					(assign,':town','p_village_1'), # should break out of the loop
				(try_end),
            (try_end),
            (call_script,'script_select_random_faction_city',':faction'),
            (assign,':origin','$return'),
            (set_spawn_radius,0),
            (spawn_around_party,':origin',':template'),
			(assign,':war_party',reg0),
            (party_set_ai_behavior,':war_party',ai_bhvr_attack_party),
            (party_set_ai_object,':war_party',':dest'),
            (faction_get_slot,':attitude',':faction',slot_faction_att_to_player),
            (party_set_slot,':war_party',slot_spawn_att_to_player,':attitude'),
            (party_set_slot,':war_party',slot_spawn_origin,':origin'),
            (party_set_slot,':war_party',slot_spawn_dest,':dest'),
            (party_set_slot,':war_party',slot_spawn_orders,orders_capture),
            (party_set_slot,':dest',slot_town_siege_attacker,':war_party'),
		(else_try),
            (eq,':mission_opt',mission_raiders_capture),
            (try_begin),
				(eq,':faction','fac_hosokawa'),
				(assign,':template','pt_hosokawa_raiders'),
            (else_try),
				(assign,':template','pt_yamana_raiders'),
            (try_end),
            (party_template_get_slot,':spawn_cost',':template',slot_template_spawn_cost),
            (faction_slot_ge,':faction',slot_faction_spawn_points,':spawn_cost'),
            (call_script,'script_object_modify_slot',obj_faction,':faction',slot_faction_spawn_points,op_sub,':spawn_cost'),
            (try_begin), # determine which cities need attacking
				(eq,':faction','fac_hosokawa'),
				(try_for_range,':village','p_village_1','p_village_17'),
					(party_get_slot,':fac',':village',slot_town_initial_faction), # compare current city faction against original order in module_parties
					(store_faction_of_party,':fac2',':village'),
					(neq,':fac',':fac2'),
					(assign,':dest',':village'),
					(assign,':town','p_village_17'), # should break out of the loop
				(try_end),
            (else_try),
				(eq,':faction','fac_yamana'),
				(try_for_range,':village','p_village_17','p_village_38'),
					(party_get_slot,':fac',':village',slot_town_initial_faction), # compare current city faction against original order in module_parties
					(store_faction_of_party,':fac2',':village'),
					(neq,':fac',':fac2'),
					(assign,':dest',':village'),
					(assign,':village','p_village_1'), # should break out of the loop
				(try_end),
            (try_end),
            (call_script,'script_select_random_faction_city',':faction'),
            (assign,':origin','$return'),
            (set_spawn_radius,0),
            (spawn_around_party,':origin',':template'),
			(assign,':raiders',reg0),
            (party_set_ai_behavior,':raiders',ai_bhvr_attack_party),
            (party_set_ai_object,':raiders',':dest'),
            (faction_get_slot,':attitude',':faction',slot_faction_att_to_player),
            (party_set_slot,':raiders',slot_spawn_att_to_player,':attitude'),
            (party_set_slot,':raiders',slot_spawn_origin,':origin'),
            (party_set_slot,':raiders',slot_spawn_dest,':dest'),
            (party_set_slot,':raiders',slot_spawn_orders,orders_capture),
            (party_set_slot,':dest',slot_town_siege_attacker,':raiders'),
		(else_try),
            (eq,':mission_opt',mission_intel),
            (party_template_get_slot,':spawn_cost','pt_spy',slot_template_spawn_cost),
            (faction_slot_ge,':faction',slot_faction_spawn_points,':spawn_cost'),
			(call_script,'script_object_modify_slot',obj_faction,':faction',slot_faction_spawn_points,op_sub,':spawn_cost'),
			(faction_get_slot,':enemy_fac',':faction',slot_faction_enemy_faction),
            (call_script,'script_select_random_faction_city',':faction'),
            (assign,':origin','$return'),
            (call_script,'script_select_random_faction_city',':enemy_fac'),
            (assign,':dest','$return'),
            (set_spawn_radius,0),
            (spawn_around_party,':origin','pt_spy'),
			(assign,':spy_party',reg0),
			(party_set_name,':spy_party','@Travelers'),
            (party_add_members,':spy_party','trp_jounin',4),
            (party_set_ai_behavior,':spy_party',ai_bhvr_travel_to_party),
            (party_set_ai_object,':spy_party',':dest'),
            (faction_get_slot,':attitude',':faction',slot_faction_att_to_player),
            (party_set_slot,':spy_party',slot_spawn_att_to_player,':attitude'),
            (party_set_slot,':spy_party',slot_spawn_origin,':origin'),
            (party_set_slot,':spy_party',slot_spawn_dest,':dest'),
            (party_set_slot,':spy_party',slot_spawn_delay,-1),
			(display_message,'@Spy party has been spawned',debug_text),
			(set_camera_follow_party,':spy_party'),
		(else_try),
            (eq,':mission_opt',mission_raiders_raid), # set up raiders, will not capture the village, need to modify siege AI
            (try_begin),
				(eq,':faction','fac_hosokawa'),
				(assign,':template','pt_hosokawa_raiders'),
				(assign,':enemy_fac','fac_yamana'),
            (else_try),
				(assign,':template','pt_yamana_raiders'),
				(assign,':enemy_fac','fac_hosokawa'),
            (try_end),
            (faction_get_slot,':spawn_cost',':template',slot_template_spawn_cost),
            (faction_slot_ge,':faction',slot_faction_spawn_points,':spawn_cost'),
            (call_script,'script_object_modify_slot',obj_faction,':faction',slot_faction_spawn_points,op_sub,':spawn_cost'),
            (call_script,'script_select_random_faction_town',':faction'),
            (assign,':origin','$return'),
            (call_script,'script_select_random_faction_village',':enemy_fac'),
            (assign,':dest','$return'),
            (set_spawn_radius,0),
            (spawn_around_party,':origin',':template'),
			(assign,':raiders',reg0),
            (party_set_ai_behavior,':raiders',ai_bhvr_attack_party),
            (party_set_ai_object,':raiders',':dest'),
            (faction_get_slot,':attitude',':faction',slot_faction_att_to_player),
            (party_set_slot,':raiders',slot_spawn_att_to_player,':attitude'),
            (party_set_slot,':raiders',slot_spawn_origin,':origin'),
            (party_set_slot,':raiders',slot_spawn_dest,':dest'),
            (party_set_slot,':dest',slot_town_siege_attacker,':raiders'),
		(try_end),
        ]
	),
      ('faction_ai_mission2',
        [
          (store_script_param_1,':faction'),
          (store_script_param_2,':mission_opt'),
          (try_begin),
            (eq,':mission_opt',mission_raiders_capture),
            (try_begin),
              (eq,':faction','fac_hosokawa'),
              (assign,':enemy_fac','fac_yamana'),
              (assign,':template','pt_hosokawa_raiders'),
              (assign,':max_raiders','$max_hosokawa_raiders'),
            (else_try),
              (assign,':template','pt_yamana_raiders'),
              (assign,':enemy_fac','fac_hosokawa'),
              (assign,':max_raiders','$max_yamana_raiders'),
            (try_end),
            (faction_get_slot,':spawn_cost',':template',slot_template_spawn_cost),
            (faction_slot_ge,':faction',slot_faction_spawn_points,':spawn_cost'),
            (call_script,'script_object_modify_slot',obj_faction,':faction',slot_faction_spawn_points,op_sub,':spawn_cost'),
            (call_script,'script_select_random_faction_city',':faction'),
            (assign,':origin','$return'),
            (call_script,'script_select_random_faction_village',':enemy_fac'),
            (assign,':dest','$return'),
            (try_for_parties,':raider'),
			  (call_script,'script_cf_party_is_of_template',':raider',':template'),
              (val_add,reg1,1),
            (try_end),
            (le,reg1,':max_raiders'),
            (set_spawn_radius,0),
            (spawn_around_party,':origin',':template'),
            (party_set_ai_behavior,reg0,ai_bhvr_attack_party),
            (party_set_ai_object,reg0,':dest'),
            (faction_get_slot,':attitude',':faction',slot_faction_att_to_player),
            (party_set_slot,reg0,slot_spawn_att_to_player,':attitude'),
            (party_set_slot,reg0,slot_spawn_origin,':origin'),
            (party_set_slot,reg0,slot_spawn_dest,':dest'),
            (party_set_slot,reg0,slot_spawn_orders,orders_capture),
            (party_set_slot,':dest',slot_town_siege_attacker,reg0),
          (else_try),
            (eq,':mission_opt',mission_army_capture),
            (try_begin),
              (eq,':faction','fac_hosokawa'),
              (assign,':enemy_fac','fac_yamana'),
              (assign,':template','pt_army'),
              (assign,':max','$max_hosokawa_armies'),
            (else_try),
              (assign,':template','pt_army'),
              (assign,':enemy_fac','fac_hosokawa'),
              (assign,':max','$max_yamana_armies'),
            (try_end),
            (party_template_get_slot,':spawn_cost',':template',slot_template_spawn_cost),
            (faction_slot_ge,':faction',slot_faction_spawn_points,':spawn_cost'),
            (call_script,'script_object_modify_slot',obj_faction,':faction',slot_faction_spawn_points,op_sub,':spawn_cost'),
            (call_script,'script_select_random_faction_city',':faction'),
            (assign,':origin','$return'),
            (call_script,'script_select_random_faction_city',':enemy_fac'),
            (assign,':dest','$return'),
            (set_spawn_radius,0),
            (assign,reg1,0),
            (try_for_parties,':army'),
              (call_script,'script_cf_party_is_of_template',':army',':template'),
              (val_add,reg1,1),
            (try_end),
            (le,reg1,':max'),
            (spawn_around_party,':origin',':template'),
            (party_set_faction,reg0,':faction'),
            (party_set_ai_behavior,reg0,ai_bhvr_attack_party),
            (party_set_ai_object,reg0,':dest'),
            (faction_get_slot,':attitude',':faction',slot_faction_att_to_player),
            (party_set_slot,reg0,slot_spawn_att_to_player,':attitude'),
            (party_set_slot,reg0,slot_spawn_origin,':origin'),
            (party_set_slot,reg0,slot_spawn_dest,':dest'),
            (party_set_slot,reg0,slot_spawn_orders,orders_capture),
            (party_set_slot,':dest',slot_town_siege_attacker,reg0),
          (else_try),
            (eq,':mission_opt',mission_war_party_capture),
            (try_begin),
              (eq,':faction','fac_hosokawa'),
              (assign,':enemy_fac','fac_yamana'),
              (assign,':template','pt_hosokawa_war_party'),
              (assign,':max','$max_hosokawa_war_parties'),
            (else_try),
              (assign,':template','pt_yamana_war_party'),
              (assign,':enemy_fac','fac_hosokawa'),
              (assign,':max','$max_yamana_war_parties'),
            (try_end),
            (faction_get_slot,':spawn_cost',':template',slot_template_spawn_cost),
            (faction_slot_ge,':faction',slot_faction_spawn_points,':spawn_cost'),
            (call_script,'script_object_modify_slot',obj_faction,':faction',slot_faction_spawn_points,op_sub,':spawn_cost'),
            (call_script,'script_select_random_faction_city',':faction'),
            (assign,':origin','$return'),
            (set_spawn_radius,0),
            (assign,reg1,0),
            (try_for_parties,':war_party'),
              (call_script,'script_cf_party_is_of_template',':war_party',':template'),
              (val_add,reg1,1),
            (try_end),
            (le,reg1,':max'),
            (spawn_around_party,':origin',':template'),
            (party_set_ai_behavior,reg0,ai_bhvr_attack_party),
            (party_set_ai_object,reg0,':dest'),
            (faction_get_slot,':attitude',':faction',slot_faction_att_to_player),
            (party_set_slot,reg0,slot_spawn_att_to_player,':attitude'),
            (party_set_slot,reg0,slot_spawn_origin,':origin'),
            (party_set_slot,reg0,slot_spawn_dest,':dest'),
            (party_set_slot,reg0,slot_spawn_orders,orders_capture),
            (party_set_slot,':dest',slot_town_siege_attacker,reg0),
          (try_end),
        ]
      ),
	  ('bandit_ai_mission',
        [
          (store_script_param_1,':mission_opt'),
          (faction_get_slot,':spawn_points','fac_outlaws',slot_faction_spawn_points),
          (try_begin),
            (eq,':mission_opt',mission_do_nothing),
          (else_try),
            (eq,':mission_opt',mission_build_fort),
            (faction_slot_ge,'fac_outlaws',slot_faction_treasury,36000),
            (call_script,'script_modify_faction_treasury','fac_outlaws',36000),
            (party_template_get_slot,':spawn_cost','pt_builder',slot_template_spawn_cost),
            (ge,':spawn_points',':spawn_cost'),
            (call_script,'script_object_modify_slot',obj_faction,'fac_outlaws',slot_faction_spawn_points,op_sub,':spawn_cost'),
            (store_random_in_range,':dest','p_city_5','p_village_1'),
            (set_spawn_radius,0),
            (spawn_around_party,'p_bandit_camp','pt_builder'),
            (party_set_faction,reg0,'fac_outlaws'),
            (party_set_ai_behavior,reg0,ai_bhvr_travel_to_party),
            (party_set_ai_object,reg0,':dest'),
            (party_set_slot,reg0,slot_spawn_origin,'p_bandit_camp'),
            (party_set_slot,reg0,slot_spawn_dest,':dest'),
            (party_set_slot,reg0,slot_spawn_gold,36000),
            (faction_get_slot,':attitude','fac_outlaws',slot_faction_att_to_player),
            (party_set_slot,reg0,slot_spawn_att_to_player,':attitude'),
            (party_add_members,reg0,'trp_mounted_bandit',10),
            (party_add_members,reg0,'trp_bandit',10),
          (else_try),
            (eq,':mission_opt',mission_bandits_raid),
          (else_try),
            (eq,':mission_opt',mission_bandits_capture_village),
          (else_try),
            (eq,':mission_opt',mission_bandits_capture_town),
          (else_try),
            (eq,':mission_opt',mission_bandits_capture_city),
          (try_end),
        ]
      ),
      ('bandit_ai_decisor',
        [
          (faction_get_slot,':score','fac_outlaws',slot_faction_strength),
          (try_begin),
            (is_between,':score',0,100),
            (store_random_in_range,reg1,0,100),
            (try_begin),
              (is_between,reg1,0,85),
              (assign,':mission_opt',mission_do_nothing),
            (else_try),
              (is_between,reg1,85,95),
              (assign,':mission_opt',mission_build_fort),
            (else_try),
              (is_between,reg1,95,100),
              (assign,':mission_opt',mission_bandits_raid),
            (try_end),
          (else_try),
            (is_between,':score',100,250),
            (store_random_in_range,reg1,0,100),
            (try_begin),
              (is_between,reg1,0,60),
              (assign,':mission_opt',mission_do_nothing),
            (else_try),
              (is_between,reg1,60,80),
              (assign,':mission_opt',mission_build_fort),
            (else_try),
              (is_between,reg1,80,90),
              (assign,':mission_opt',mission_bandits_raid),
            (else_try),
              (is_between,reg1,90,100),
              (assign,':mission_opt',mission_bandits_capture_village),
            (try_end),
          (else_try),
            (is_between,':score',250,500),
            (store_random_in_range,reg1,0,100),
            (try_begin),
              (is_between,reg1,0,40),
              (assign,':mission_opt',mission_do_nothing),
            (else_try),
              (is_between,reg1,40,65),
              (assign,':mission_opt',mission_bandits_raid),
            (else_try),
              (is_between,reg1,65,90),
              (assign,':mission_opt',mission_bandits_capture_village),
            (else_try),
              (is_between,reg1,90,100),
              (assign,':mission_opt',mission_bandits_capture_town),
            (try_end),
          (else_try),
            (ge,':score',500),
            (store_random_in_range,reg1,0,100),
            (try_begin),
              (is_between,reg1,0,30),
              (assign,':mission_opt',mission_do_nothing),
            (else_try),
              (is_between,reg1,30,50),
              (assign,':mission_opt',mission_bandits_raid),
            (else_try),
              (is_between,reg1,50,75),
              (assign,':mission_opt',mission_bandits_capture_village),
            (else_try),
              (is_between,reg1,75,90),
              (assign,':mission_opt',mission_bandits_capture_town),
            (else_try),
              (is_between,reg1,90,100),
              (assign,':mission_opt',mission_bandits_capture_city),
            (try_end),
          (try_end),
          (assign,'$return',':mission_opt'),
        ]
      ),
      ###################################################################################################
      #################################### Spawn functions ######################################################
      ###################################################################################################

	  #script add food to travelling farmers
('add_rice_to_travelling_merchant',
	[
		(store_script_param_1,':town'),
		(store_script_param_2,':merchant'),
		(store_script_param,':party_type',3),
		(party_get_slot,':town_food_stores',':town',slot_town_food_stores),
		(party_get_slot,':town_size',':town',slot_town_size),
		(try_begin),
			(eq,':town_size',ct_small_village),
			(assign,':min_bushels',3),
		(else_try),
			(eq,':town_size',ct_village),
			(assign,':min_bushels',5),
		(else_try),
			(eq,':town_size',ct_large_village),
			(assign,':min_bushels',10),
		(else_try),
			(eq,':town_size',ct_town),
			(assign,':min_bushels',5),
		(else_try),
			(eq,':town_size',ct_large_town),
			(assign,':min_bushels',7),
		(try_end),
		(store_random_in_range,':extra_bushels',0,21),
		(store_add,':bushels',':min_bushels',':extra_bushels'),
		(val_clamp,':bushels',0,21),
		(val_mul,':bushels',360),
		(try_begin),
			(eq,':party_type',spt_merchant),
			(val_div,':bushels',2),
		(try_end),
		(party_set_slot,':merchant',slot_spawn_food,':bushels'),
		(val_sub,':town_food_stores',':bushels'),
		(val_max,':town_food_stores',0),
		(party_set_slot,':town',slot_town_food_stores,':town_food_stores'),
		]
	),
     
# script spawn local_patrol
('cf_spawn_local_patrol',
	[
		(store_script_param,':town',1),
		(store_script_param,':template',2),
		(party_slot_eq,':town',slot_town_patrol_active,0),
		(party_template_get_slot,':template_spawn_cost',':template',slot_template_spawn_cost),
		(call_script,'script_get_upper_lower_bounds',':template_spawn_cost',10),
		(assign,':lower_bound',reg0),
		(assign,':upper_bound',reg1),
		(store_random_in_range,':spawn_cost',':lower_bound',':upper_bound'),
		(party_slot_ge,':town',slot_town_spawn_points,':spawn_cost'),
		(call_script,'script_object_modify_slot',obj_party,':town',slot_town_spawn_points,op_sub,':spawn_cost'),
		(set_spawn_radius,0),
		(spawn_around_party,':town','pt_local_patrol'),
		(assign,':patrol',reg0),
		(call_script,'script_party_add_party_reinforcements',':patrol',':town',':spawn_cost'),
		(party_set_ai_behavior,':patrol',ai_bhvr_patrol_party),
		(party_set_ai_object,':patrol',':town'),
		(party_set_ai_patrol_radius,':patrol',15),
		(party_set_slot,':town',slot_town_patrol,':patrol'),
		(party_set_slot,':town',slot_town_patrol_active,1),
		(party_set_slot,':patrol',slot_spawn_origin,':town'),
		(store_faction_of_party,':faction',':town'),
		(party_set_faction,':patrol',':faction'),
		(party_get_slot,':attitude',':town',slot_town_att_to_player),
		(party_set_slot,':patrol',slot_spawn_att_to_player,':attitude'),
		(party_set_slot,':patrol',slot_spawn_ai_state,spai_patrolling_around_center),
		(party_set_slot,':patrol',slot_spawn_ai_object,':town'),
		(party_set_slot,':patrol',slot_spawn_type,spt_patrol),
		(party_get_slot,':size',':town',slot_town_size),
		(try_begin),
			(this_or_next|eq,':size',ct_town),
			(this_or_next|eq,':size',ct_large_town),
			(this_or_next|eq,':size',ct_city),
			(eq,':size',ct_port),
			(party_set_icon,':patrol','icon_gray_knight'),
		(try_end),
        ]
	),
# script_cf_faction_hero_party
('cf_faction_spawn_hero_party',
	[
		(store_script_param,':faction',1),
		(store_script_param,':lower_points_limit',2),
		(store_script_param,':upper_points_limit',3),
		(store_random_in_range,':spawn_points',':lower_points_limit',':upper_points_limit'),
		(faction_slot_ge,':faction',slot_faction_spawn_points,':spawn_points'),
		(call_script,'script_cf_faction_get_available_hero',':faction'),
		(call_script,'script_object_modify_slot',obj_faction,':faction',slot_faction_spawn_points,op_sub,':spawn_points'),
		(assign,':hero',reg0),
		(troop_get_slot,':hero_town',':hero',slot_troop_city),
		(set_spawn_radius,0),
		(spawn_around_party,':hero_town','pt_empty_template'),
		(assign,':hero_party',reg0),
		(party_add_members,':hero_party',':hero',1),
		(call_script,'script_faction_add_faction_reinforcements',':hero_party',':faction',':spawn_points'),
		]
	),
# script_cf_faction_get_available_hero
('cf_faction_get_available_hero',
	[
		(store_script_param,':faction',1),
		(assign,':temp_array_index',0),
		(try_for_range,':troop_no',npc_lords_begin,npc_lords_end),
			(store_troop_faction,':troop_fac',':troop_no'),
			(call_script,'script_cf_faction_is_ally_of_faction',':troop_fac',':faction'),
			(troop_slot_eq,':troop_no',slot_troop_active,false),
			(troop_set_slot,'trp_temp_array_a',':temp_array_index',':troop_no'),
			(val_add,':temp_array_index',1),
		(try_end),
		(assign,':array_length',':temp_array_index'),
		(store_random_in_range,':temp_array_index',0,':array_length'),
		(troop_get_slot,reg0,'trp_temp_array_a',':temp_array_index'),
		]
	),
# script_cf_faction_spawn_patrol
('cf_faction_spawn_patrol',
	[
		(store_script_param,':faction',1),
		(store_script_param,':template',2),
		(party_template_get_slot,':template_spawn_cost',':template',slot_template_spawn_cost),
		(call_script,'script_get_upper_lower_bounds',':template_spawn_cost',20),
		(assign,':lower_bound',reg0),
		(assign,':upper_bound',reg1),
		(store_random_in_range,':spawn_cost',':lower_bound',':upper_bound'),
		(faction_slot_ge,':faction',slot_faction_spawn_points,':spawn_cost'),
		(call_script,'script_object_modify_slot',obj_faction,':faction',slot_faction_spawn_points,op_sub,':spawn_cost'),
		(call_script,"script_select_random_faction_town",':faction'),
		(assign,':origin','$return'),
		(set_spawn_radius,1),
		(spawn_around_party,':origin',":template"),
		(assign,':patrol',reg0),
		(call_script,'script_object_modify_slot',obj_party,':patrol',slot_spawn_type,op_asn,spt_patrol),
		(call_script,'script_object_modify_slot',obj_party,':patrol',slot_spawn_ai_state,op_asn,spai_patroling),
		(call_script,'script_object_modify_slot',obj_party,':patrol',slot_spawn_ai_object,op_asn,null),
		(call_script,'script_object_modify_slot',obj_party,':patrol',slot_spawn_origin,op_asn,':origin'),
		(call_script,'script_faction_add_faction_reinforcements',':patrol',':faction',':spawn_cost'),
		(faction_get_slot,':att_to_player',':faction',slot_faction_att_to_player),
		(party_set_slot,':patrol',slot_spawn_att_to_player,':att_to_player'),
		]
	),
# script_cf_faction_spawn_army
('cf_faction_spawn_army',
	[
		(store_script_param,':faction',1),
		(store_script_param,':lower_limit',2),
		(store_script_param,':upper_limit',3),
		(store_script_param,':has_hero_commander',4),
		(store_script_param,':spawn_location',5),
		(store_random_in_range,':spawn_cost',':lower_limit',':upper_limit'),
		(faction_slot_ge,':faction',slot_faction_spawn_points,':spawn_cost'),
		(try_begin),
			(eq,':has_hero_commander',true),
			(call_script,'script_cf_faction_get_available_hero',':faction'),
			(assign,':general',reg0),
			(troop_get_slot,':spawn_location',':general',slot_troop_city),
		(else_try),
			(assign,':general','trp_taisho'),
		(try_end),
		(call_script,'script_object_modify_slot',obj_faction,':faction',slot_faction_spawn_points,op_sub,':spawn_cost'),
		(set_spawn_radius,0),
		(spawn_around_party,':spawn_location','pt_army'),
		(assign,':army',reg0),
		(party_add_members,':army',':general',1),
		(call_script,'script_faction_add_faction_reinforcements',':army',':faction',':spawn_cost'),
		(str_store_faction_name,s11,':faction'),
		(str_store_string,s10,'@{s11} Army'),
		(party_set_name,':army',s10),
		(party_set_faction,':army',':faction'),
		(party_get_num_companions,':army_size',':army'),
		(call_script,'script_object_modify_slot',obj_party,':army',slot_army_size,op_asn,':army_size'),
		(call_script,'script_object_modify_slot',obj_party,':army',slot_army_base,op_asn,':spawn_location'),
		]
	),
# script_faction_add_faction_reinforcements
('faction_add_faction_reinforcements',
	[
		(store_script_param,':party_no',1),
		(store_script_param,':faction',2),
		(store_script_param,':spawn_points',3),
		(faction_get_slot,':reinforcements_template_a',':faction',slot_faction_reinforcements_a),
		(faction_get_slot,':reinforcements_template_b',':faction',slot_faction_reinforcements_b),
		(faction_get_slot,':reinforcements_template_c',':faction',slot_faction_reinforcements_c),
		(faction_get_slot,':reinforcements_template_d',':faction',slot_faction_reinforcements_d),
		(party_template_get_slot,':reinforcements_a_cost',':reinforcements_template_a',slot_template_spawn_cost),
		(party_template_get_slot,':reinforcements_b_cost',':reinforcements_template_b',slot_template_spawn_cost),
		(party_template_get_slot,':reinforcements_c_cost',':reinforcements_template_c',slot_template_spawn_cost),
		(party_template_get_slot,':reinforcements_d_cost',':reinforcements_template_d',slot_template_spawn_cost),
		(try_begin),
			(ge,':spawn_points',':reinforcements_a_cost'),
			(val_sub,':spawn_points',':reinforcements_a_cost'),
			(party_add_template,':party_no',':reinforcements_template_a'),
		(try_end),
		(try_begin),
			(ge,':spawn_points',':reinforcements_b_cost'),
			(val_sub,':spawn_points',':reinforcements_b_cost'),
			(party_add_template,':party_no',':reinforcements_template_b'),
		(try_end),
		(try_begin),
			(ge,':spawn_points',':reinforcements_c_cost'),
			(val_sub,':spawn_points',':reinforcements_c_cost'),
			(party_add_template,':party_no',':reinforcements_template_c'),
		(try_end),
		(try_begin),
			(ge,':spawn_points',':reinforcements_d_cost'),
			(val_sub,':spawn_points',':reinforcements_d_cost'),
			(party_add_template,':party_no',':reinforcements_template_d'),
		(try_end),
		(try_begin),
			(ge,':spawn_points',':reinforcements_d_cost'),
			(call_script,'script_faction_add_faction_reinforcements',':party_no',':faction',':spawn_points'),
		(try_end),
		]
	),
# script_party_add_party_reinforcements
('party_add_party_reinforcements',
	[
		(store_script_param,':party_no',1),
		(store_script_param,':origin',2),
		(store_script_param,':spawn_points',3),
		(party_get_slot,':template_a',':origin',slot_town_reinforcements_a),
		(party_get_slot,':template_b',':origin',slot_town_reinforcements_b),
		(party_get_slot,':template_c',':origin',slot_town_reinforcements_c),
		(party_template_get_slot,':cost_a',':template_a',slot_template_spawn_cost),
		(party_template_get_slot,':cost_b',':template_b',slot_template_spawn_cost),
		(party_template_get_slot,':cost_c',':template_c',slot_template_spawn_cost),
		(try_begin),
			(ge,':spawn_points',':cost_a'),
			(val_sub,':spawn_points',':cost_a'),
			(party_add_template,':party_no',':template_a'),
		(try_end),
		(try_begin),
			(ge,':spawn_points',':cost_b'),
			(val_sub,':spawn_points',':cost_b'),
			(party_add_template,':party_no',':template_b'),
		(try_end),
		(try_begin),
			(ge,':spawn_points',':cost_c'),
			(val_sub,':spawn_points',':cost_c'),
			(party_add_template,':party_no',':template_c'),
		(try_end),
		(try_begin),
			(ge,':spawn_points',':cost_c'),
			(call_script,'script_party_add_party_reinforcements',':party_no',':origin',':spawn_points'),
		(try_end),
		]
	),
# script_update_reinforcement_spawn_cost
('update_reinforcement_spawn_cost',
	[
		(store_random_in_range,reg10,36000,44000),
		(store_random_in_range,reg11,9000,11000),
		(store_random_in_range,reg12,4500,5500),
		(store_random_in_range,reg13,900,1100),
		(party_template_set_slot,'pt_hosokawa_reinforcements_a',slot_template_spawn_cost,reg10),
		(party_template_set_slot,'pt_hosokawa_reinforcements_b',slot_template_spawn_cost,reg11),
		(party_template_set_slot,'pt_hosokawa_reinforcements_c',slot_template_spawn_cost,reg12),
		(party_template_set_slot,'pt_hosokawa_reinforcements_d',slot_template_spawn_cost,reg13),
		(store_random_in_range,reg10,36000,44000),
		(store_random_in_range,reg11,9000,11000),
		(store_random_in_range,reg12,4500,5500),
		(store_random_in_range,reg13,900,1100),
		(party_template_set_slot,'pt_yamana_reinforcements_a',slot_template_spawn_cost,reg10),
		(party_template_set_slot,'pt_yamana_reinforcements_b',slot_template_spawn_cost,reg11),
		(party_template_set_slot,'pt_yamana_reinforcements_c',slot_template_spawn_cost,reg12),
		(party_template_set_slot,'pt_yamana_reinforcements_d',slot_template_spawn_cost,reg13),
		(store_random_in_range,reg10,450,550),
		(store_random_in_range,reg11,225,275),
		(store_random_in_range,reg12,90,110),
		(party_template_set_slot,'pt_village_reinforcements_a',slot_template_spawn_cost,reg10),
		(party_template_set_slot,'pt_village_reinforcements_b',slot_template_spawn_cost,reg11),
		(party_template_set_slot,'pt_village_reinforcements_c',slot_template_spawn_cost,reg12),
		(store_random_in_range,reg10,1800,2200),
		(store_random_in_range,reg11,900,1100),
		(store_random_in_range,reg12,270,330),
		(party_template_set_slot,'pt_town_reinforcements_a',slot_template_spawn_cost,reg10),
		(party_template_set_slot,'pt_town_reinforcements_b',slot_template_spawn_cost,reg11),
		(party_template_set_slot,'pt_town_reinforcements_c',slot_template_spawn_cost,reg12),
		(store_random_in_range,reg10,3150,3850),
		(store_random_in_range,reg11,1800,2200),
		(store_random_in_range,reg12,450,550),
		(party_template_set_slot,'pt_city_reinforcements_a',slot_template_spawn_cost,reg10),
		(party_template_set_slot,'pt_city_reinforcements_b',slot_template_spawn_cost,reg11),
		(party_template_set_slot,'pt_city_reinforcements_c',slot_template_spawn_cost,reg12),
		]
	),
########################################### Agent Functions #############################################
#################################################################################################
# agent morale
# ('agent_cf_check_morale',
	# [
		# (store_script_param,':agent_no',1),
		# (agent_is_human,':agent_no'),
		# (agent_is_alive,':agent_no'),
		# (store_agent_hit_points,':agent_hit_points',':agent_no'),
		# (assign,':chance_to_run',0),
		# (try_begin),
			# (is_between,':agent_hit_points',0,10),
			# (val_add,':chance_to_run',30),
		# (else_try),
			# (is_between,':agent_hit_points',10,25),
			# (val_add,':chance_to_run',20),
		# (else_try),
			# (is_between,':agent_hit_points',25,50),
			# (val_add,':chance_to_run',10),
		# (else_try),
			# (is_between,':agent_hit_points',50,75),
			# (val_add,':chance_to_run',5),
		# (else_try),
			# (is_between,':agent_hit_points',75,100),
			# (val_add,':chance_to_run',1),
		# (try_end),
		# (store_random_in_range,':roll',0,100),
		# (lt,':roll',':chance_to_run'),
		# ]
	# ),
('update_team_morale',
	[
		(assign,':sum_enemy_hp',0),
		(assign,':sum_ally_hp',0),
		# (assign,':num_enemies',0),
		# (assign,':num_allies',0),
		(try_for_agents,':agent_no'),
			(agent_is_human,':agent_no'),
			(agent_is_alive,':agent_no'),
			(store_agent_hit_points,':agent_hp',':agent_no'),
			(agent_get_team,':agent_team',':agent_no'),
			(try_begin),
				(eq,':agent_team','$g_enemy_team'),
				(call_script,'script_object_modify_slot',obj_agent,':agent_no',slot_agent_morale,op_asn,':agent_hp'),
				(val_add,':sum_enemy_hp',':agent_hp'),
			(else_try),
				(call_script,'script_object_modify_slot',obj_agent,':agent_no',slot_agent_morale,op_asn,':agent_hp'),
				(val_add,':sum_ally_hp',':agent_hp'),
			(try_end),
		(try_end),
		(store_div,':player_team_morale',':sum_ally_hp','$g_ally_size'),
		(store_div,':enemy_team_morale',':sum_enemy_hp','$g_enemy_size'),
		(val_clamp,':player_team_morale',0,101),
		(val_clamp,':enemy_team_morale',0,101),
		(assign,'$g_player_team_morale',':player_team_morale'),
		(assign,'$g_enemy_team_morale',':enemy_team_morale'),
		# (assign,reg10,'$g_player_team_morale'),
		# (assign,reg11,'$g_enemy_team_morale'),
		# (display_message,'@Morale update: Player: {reg10}; Enemy: {reg11}',debug_text),
		]
	),
('cf_process_team_reinforcements',
	[
		(store_script_param,':agent_no',1),
		(agent_is_alive,':agent_no'),
		(agent_is_human,':agent_no'),
		(agent_get_party_id,':agent_party',':agent_no'),
		(agent_get_team,':agent_team',':agent_no'),
		(try_begin),
			(this_or_next|eq,':agent_team','$g_player_team'),
			(eq,':agent_team','$g_enemy_team'),
		(else_try),
			(this_or_next|eq,':agent_party','p_main_party'),
			(agent_is_ally,':agent_no'),
			(agent_set_team,':agent_no','$g_player_team'),
			(store_agent_hit_points,':agent_hp',':agent_no'),
			(call_script,'script_object_modify_slot',obj_agent,':agent_no',slot_agent_morale,op_asn,':agent_hp'),
			(val_add,'$g_ally_size',1),
		(else_try),
			(agent_set_team,':agent_no','$g_enemy_team'),
			(store_agent_hit_points,':agent_hp',':agent_no'),
			(call_script,'script_object_modify_slot',obj_agent,':agent_no',slot_agent_morale,op_asn,':agent_hp'),
			(val_add,'$g_enemy_size',1),
		(try_end),
		]
	),
# script_agent_get_valid_retreat_position
('agent_get_valid_retreat_position',
	[
		(store_script_param,':opt',1),
		(store_script_param,':minx',2),
		(store_script_param,':miny',3),
		(store_script_param,':maxx',4),
		(store_script_param,':maxy',5),
		(store_script_param,':playerx',6),
		(store_script_param,':playery',7),
		(store_script_param,':enemyx',8),
		(store_script_param,':enemyy',9),
		(store_div,':midx',':maxx',2),
		(store_div,':midy',':maxy',2),
		(assign,':player_quadrant',0),
		(assign,':enemy_quadrant',0),
		(try_begin),
			(is_between,':playerx',':minx',':midx'),
			(is_between,':playery',':miny',':midy'),
			(assign,':player_quadrant',1),
		(else_try),
			(is_between,':playerx',':midx',':maxx'),
			(is_between,':playery',':miny',':midy'),
			(assign,':player_quadrant',2),
		(else_try),
			(is_between,':playerx',':minx',':midx'),
			(is_between,':playery',':midy',':maxy'),
			(assign,':player_quadrant',3),
		(else_try),
			(is_between,':playerx',':midx',':maxx'),
			(is_between,':playery',':midy',':maxy'),
			(assign,':player_quadrant',4),
		(try_end),
		(try_begin),
			(is_between,':enemyx',':minx',':midx'),
			(is_between,':enemyy',':miny',':midy'),
			(assign,':enemy_quadrant',1),
		(else_try),
			(is_between,':enemyx',':midx',':maxx'),
			(is_between,':enemyy',':miny',':midy'),
			(assign,':enemy_quadrant',2),
		(else_try),
			(is_between,':enemyx',':minx',':midx'),
			(is_between,':enemyy',':midy',':maxy'),
			(assign,':enemy_quadrant',3),
		(else_try),
			(is_between,':enemyx',':midx',':maxx'),
			(is_between,':enemyy',':midy',':maxy'),
			(assign,':enemy_quadrant',4),
		(try_end),
		(try_begin),
			(eq,':opt',0),
			(call_script,'script_agent_get_retreat_position',':maxx',':maxy',':enemy_quadrant'),
		(else_try),
			(eq,':opt',1),
			(call_script,'script_agent_get_retreat_position',':maxx',':maxy',':player_quadrant'),
		(try_end),
		]
	),
# script_agent_get_retreat_position - recursive
('agent_get_retreat_position',
	[
		(store_script_param,':maxx',1),
		(store_script_param,':maxy',2),
		(store_script_param,':enemy_home_quadrant',3),
		(store_random_in_range,':target_quadrant',1,5),
		(try_begin),
			(neq,':target_quadrant',':enemy_home_quadrant'),
			(store_div,':delx',':maxx',4),
			(store_div,':dely',':maxy',4),
			(assign,':qtrx',':delx'),
			(assign,':qtry',':dely'),
			(store_sub,':threeqtrx',':maxx',':delx'),
			(store_sub,':threeqtry',':maxy',':dely'),
			(assign,':minx',0),
			(assign,':miny',0),
			(try_begin),
				(eq,':target_quadrant',1),
				(store_random_in_range,reg0,':minx',':qtrx'),
				(store_random_in_range,reg1,':miny',':qtry'),
			(else_try),
				(eq,':target_quadrant',1),
				(store_random_in_range,reg0,':threeqtrx',':maxx'),
				(store_random_in_range,reg1,':miny',':qtry'),
			(else_try),
				(eq,':target_quadrant',1),
				(store_random_in_range,reg0,':minx',':qtrx'),
				(store_random_in_range,reg1,':threeqtry',':maxy'),
			(else_try),
				(eq,':target_quadrant',1),
				(store_random_in_range,reg0,':threeqtrx',':maxx'),
				(store_random_in_range,reg1,':threeqtry',':maxy'),
			(try_end),
		(else_try),
			(call_script,'script_agent_get_retreat_position',':maxx',':maxy',':enemy_home_quadrant'),
		(try_end),
		]
	),
      ###################################################################################################
      #################################### Fort functions ######################################################
      ###################################################################################################
      ('spawn_builder',
        [
          (store_script_param_1,':town'),
          (set_spawn_radius,1),
          (spawn_around_party,':town','pt_builder'),
          (store_faction_of_party,':faction',':town'),
          (try_begin),
            (faction_slot_eq,':faction',slot_faction_hosokawa_ally,1),
            (party_add_members,reg0,'trp_t2_spear_samurai_h',3),
            (party_add_members,reg0,'trp_t2_crossbow_ashigaru_h',5),
            (party_add_members,reg0,'trp_farmer',5),
          (else_try),
            (faction_slot_eq,':faction',slot_faction_yamana_ally,1),
            (party_add_members,reg0,'trp_t2_spear_samurai_y',3),
            (party_add_members,reg0,'trp_t2_crossbow_ashigaru_y',5),
            (party_add_members,reg0,'trp_farmer',5),
          (try_end),
          (party_set_ai_behavior,reg0,ai_bhvr_hold),
          (party_set_faction,reg0,':faction'),
          (party_set_slot,reg0,slot_spawn_att_to_player,att_generous),
        ]
      ),
      
      
      ('build_fort',
        [
          (store_script_param_1,':input_party'),
          (set_spawn_radius,0),
          (spawn_around_party,':input_party','pt_fort'),
          (call_script,'script_party_add_party',reg0,':input_party'),
          (remove_party,':input_party'),
          (party_set_ai_behavior,reg0,ai_bhvr_hold),
          (party_set_slot,reg0,slot_castle_treasury,3600),
          (party_set_faction,reg0,'fac_player_faction'),
          (party_set_slot,reg0,slot_castle_progress,0),
        ]
      ),
      
('fort',
	[
		(try_for_parties,':fort'),
			(call_script,'script_cf_party_is_of_template',':fort','pt_fort'), # check/update building progress
			(try_begin),
				(party_slot_lt,':fort',slot_castle_progress,1000),
				(party_get_slot,':available_cash',':fort',slot_castle_treasury),
				(try_begin),
					(ge,reg2,1800), # set to 1800
					(assign,':cost',1800),
					(assign,':addl_progress',200),
				(else_try),
					(assign,':cost',':available_cash'),
					(assign,':addl_progress',':available_cash'),
				(try_end),
				(call_script,'script_object_modify_slot',obj_party,':fort',slot_castle_treasury,op_sub,':cost'),
				(call_script,'script_object_modify_slot',obj_party,':fort',slot_castle_progress,op_add,':addl_progress'),
			(else_try),
				(party_count_members_of_type,':troop_count',':fort','trp_geomancer'),
				(gt,':troop_count',0),
				(party_remove_members,':fort','trp_geomancer',':troop_count'),
				(try_begin),
					(store_faction_of_party,':faction',':fort'),
					(eq,':faction','fac_player_faction'),
					(assign,'$fort_complete',1),
				(try_end),
			(try_end),
		(try_end),
		]
	),
      ('spawn_fort_patrol',
        [
          (store_script_param_1,':fort'),
          (store_script_param_2,':patrol_str'),
          (set_spawn_radius,0),
          (spawn_around_party,':fort','pt_fort_patrol'),
          (assign,':patrol',reg0),
          (party_set_slot,':fort',slot_castle_patrol,':patrol'),
          (party_set_slot,':fort',slot_castle_patrol_active,1),
          (party_get_num_companion_stacks,':num_stacks',':fort'),
          (try_for_range,':i',0,':num_stacks'),
            (party_stack_get_troop_id,':troop_id',':fort',':i'),
            (party_stack_get_size,':troop_count',':fort',':i'),
            (val_div,':troop_count',':patrol_str'),
            (neq,':troop_id',-1),
            (party_add_members,':patrol',':troop_id',':troop_count'),
            (party_remove_members,':fort',':troop_id',':troop_count'),
          (try_end),
          (party_get_slot,':orders',':fort',slot_castle_patrol_orders),
          (party_get_slot,':target',':fort',slot_castle_patrol_target),
          (store_faction_of_party,':faction',':fort'),
          (faction_get_slot,':attitude',':faction',slot_faction_att_to_player),
		  (party_set_ai_behavior,':patrol',':orders'),
          (party_set_ai_object,':patrol',':target'),
          (party_set_slot,':patrol',slot_spawn_origin,':fort'),
          (party_set_faction,':patrol',':faction'),
          (party_set_slot,':patrol',slot_spawn_att_to_player,':attitude'),
        ]
      ),
      ('cf_fort_patrol_behavior',
        [
          (store_script_param_1,':fort'),
          (party_get_slot,':patrol',':fort',slot_castle_patrol),
          (party_is_active,':patrol'),
          (party_is_in_town,':patrol',':fort'),
          (call_script,'script_party_add_party',':fort',':patrol'),
          (remove_party,':patrol'),
          (party_set_slot,':fort',slot_castle_patrol,-1),
          (party_set_slot,':fort',slot_castle_patrol_active,0),
        ]
      ),
      ###################################################################################################
      #################################### Civil unrest functions  #################################################
      ###################################################################################################
      
      ###################################################################################################
      #################################### Systems #########################################################
      ##################################################################################################
	  #refresh garrison source parties
('refresh_garrison_source_parties',
	[
		(party_get_num_companions,':garrison','p_village_garrison_source'),
		(try_begin),
			(lt,':garrison',1000),
			(party_add_members,'p_village_garrison_source','trp_veteran_defender',2),
			(party_add_members,'p_village_garrison_source','trp_village_defender',2),
			(party_add_members,'p_village_garrison_source','trp_farmer',2),
			(party_add_members,'p_village_garrison_source','trp_villager',2),
		(try_end),
		(party_get_num_companions,':garrison','p_town_garrison_source'),
		(try_begin),
			(lt,':garrison',1000),
			(party_add_members,'p_town_garrison_source','trp_t2_light_cav_n',2),
			(party_add_members,'p_town_garrison_source','trp_t2_spear_samurai_n',2),
			(party_add_members,'p_town_garrison_source','trp_t2_crossbow_ashigaru_n',2),
		(try_end),
		(party_get_num_companions,':garrison','p_city_garrison_source'),
		(try_begin),
			(lt,':garrison',1000),
			(party_add_members,'p_city_garrison_source','trp_t3_heavy_cav_n',2),
			(party_add_members,'p_city_garrison_source','trp_t3_light_cav_n',2),
			(party_add_members,'p_city_garrison_source','trp_t2_spear_samurai_n',2),
			(party_add_members,'p_city_garrison_source','trp_t2_bow_ashigaru_n',2),
		(try_end),
		]
	),
      # join faction
      ('join_faction',
        [
          (store_script_param_1,':faction'),
          (store_script_param_2,':class'),
		  (faction_get_slot,':enemy_faction',':faction',slot_faction_enemy_faction),
		  (troop_set_slot,'trp_player',slot_player_rank_ptr,0),
          (store_relation,reg0,':faction',"fac_player_faction"),
          (val_max,reg0,10),
          (set_relation,':faction',"fac_player_faction", reg0),
          (try_begin),
            (neq,':class','qst_class_ronin'),
            (store_relation,reg0,':enemy_faction',"fac_player_faction"),
            (val_min,reg0,-10),
            (set_relation,':enemy_faction',"fac_player_faction", reg0),
          (try_end),
		  (faction_set_slot,':faction',slot_faction_joined,true),
          (try_begin),
            (eq,':faction','fac_hosokawa'),
			(set_relation,"fac_akamatsu","fac_player_faction", 3),
            (set_relation,"fac_hosokawa_hatakeyama","fac_player_faction", 3),
            (set_relation,"fac_takeda","fac_player_faction", 3),
            (troop_set_slot,"trp_player",slot_player_relation_hosokawa,rel_ally),
            (try_begin),
              (neq,':class','qst_class_ronin'),
              (set_relation,"fac_yamana_hatakeyama","fac_player_faction", -4),
              (set_relation,"fac_ishikki","fac_player_faction", -4),
              (set_relation,"fac_rokkaku","fac_player_faction", -4),
              (set_relation,"fac_toki","fac_player_faction", -4),
              (set_relation,"fac_shiba","fac_player_faction", -4),
              (troop_set_slot,"trp_player",slot_player_relation_yamana,rel_enemy),
            (try_end),
            (set_relation,"fac_ikko_ikki","fac_player_faction", -5),
            # (assign,"$kuge_party_template","pt_hosokawa_kuge"),
          (else_try),
            (eq,':faction','fac_yamana'),
			(set_relation,"fac_yamana_hatakeyama","fac_player_faction", 3),
            (set_relation,"fac_ishikki","fac_player_faction",3),
            (set_relation,"fac_rokkaku","fac_player_faction",3),
            (set_relation,"fac_toki","fac_player_faction",3),
            (set_relation,"fac_shiba","fac_player_faction",3),
            (troop_set_slot,"trp_player",slot_player_relation_yamana,rel_ally),
            (try_begin),
              (neq,':class','qst_class_ronin'),
              (set_relation,"fac_akamatsu","fac_player_faction", -4),
              (set_relation,"fac_hosokawa_hatakeyama","fac_player_faction", -4),
              (set_relation,"fac_takeda","fac_player_faction", -4),
              (troop_set_slot,"trp_player",slot_player_relation_hosokawa,rel_enemy),
            (try_end),
            (set_relation,"fac_ikko_ikki","fac_player_faction", -5),
            # (assign,"$kuge_party_template","pt_yamana_kuge"),
          (try_end),
          (try_begin),
            (eq,':faction','fac_hosokawa'),
            (store_random_in_range,reg6,0,6),
            (store_add,reg7,"trp_takase_shugo",reg6),
            (troop_set_slot,"trp_player",slot_player_lord,reg7),
            (try_begin),
              (eq,reg7,"trp_takase_shugo"),
              (troop_set_slot,"trp_player",slot_player_town,takase),
              (troop_set_slot,"trp_player",slot_player_castle,"scn_manor"),
              (assign,reg8,takase),
            (else_try),
              (eq,reg7,"trp_sakai_shugo"),
              (troop_set_slot,"trp_player",slot_player_town,sakai),
              (troop_set_slot,"trp_player",slot_player_castle,"scn_manor"),
              (assign,reg8,sakai),
            (else_try),
              (eq,reg7,"trp_himeji_shugo"),
              (troop_set_slot,"trp_player",slot_player_town,himeji),
              (troop_set_slot,"trp_player",slot_player_castle,"scn_manor"),
              (assign,reg8,himeji),
            (else_try),
              (eq,reg7,"trp_kameyama_shugo"),
              (troop_set_slot,"trp_player",slot_player_town,kameyama),
              (troop_set_slot,"trp_player",slot_player_castle,"scn_manor"),
              (assign,reg8,kameyama),
            (else_try),
              (eq,reg7,"trp_otsu_shugo"),
              (troop_set_slot,"trp_player",slot_player_town,otsu),
              (troop_set_slot,"trp_player",slot_player_castle,"scn_manor"),
              (assign,reg8,otsu),
            (else_try),
              (eq,reg7,"trp_obama_shugo"),
              (troop_set_slot,"trp_player",slot_player_town,obama),
              (troop_set_slot,"trp_player",slot_player_castle,"scn_manor"),
              (assign,reg8,obama),
            (try_end),
          (else_try),
            (eq,':faction','fac_yamana'),
            (store_random_in_range,reg6,0,7),
            (store_add,reg7,"trp_hidaka_shugo",reg6),
            (troop_set_slot,"trp_player",slot_player_lord,reg7),
            (try_begin),
              (eq,reg7,"trp_hidaka_shugo"),
              (troop_set_slot,"trp_player",slot_player_town,hidaka),
              (troop_set_slot,"trp_player",slot_player_castle,"scn_manor"),
              (assign,reg8,hidaka),
            (else_try),
              (eq,reg7,"trp_miyazu_shugo"),
              (troop_set_slot,"trp_player",slot_player_town,miyazu),
              (troop_set_slot,"trp_player",slot_player_castle,"scn_manor"),
              (assign,reg8,miyazu),
            (else_try),
              (eq,reg7,"trp_tsuruga_shugo"),
              (troop_set_slot,"trp_player",slot_player_town,tsuruga),
              (troop_set_slot,"trp_player",slot_player_castle,"scn_manor"),
              (assign,reg8,tsuruga),
            (else_try),
              (eq,reg7,"trp_nara_shugo"),
              (troop_set_slot,"trp_player",slot_player_town,nara),
              (troop_set_slot,"trp_player",slot_player_castle,"scn_manor"),
              (assign,reg8,nara),
            (else_try),
              (eq,reg7,"trp_fujidera_shugo"),
              (troop_set_slot,"trp_player",slot_player_town,fujidera),
              (troop_set_slot,"trp_player",slot_player_castle,"scn_manor"),
              (assign,reg8,fujidera),
            (else_try),
              (eq,reg7,"trp_ueno_shugo"),
              (troop_set_slot,"trp_player",slot_player_town,ueno),
              (troop_set_slot,"trp_player",slot_player_castle,"scn_manor"),
              (assign,reg8,ueno),
            (else_try),
              (eq,reg7,"trp_wakayama_shugo"),
              (troop_set_slot,"trp_player",slot_player_town,wakayama),
              (troop_set_slot,"trp_player",slot_player_castle,"scn_manor"),
              (assign,reg8,wakayama),
            (try_end),
          (try_end),
          (try_begin),
            (check_quest_active,'qst_class_bushi'),
            (assign,'$shugo_storyline_quest_array','$bushi_storyline_quest_array'),
          (else_try),
            (check_quest_active,'qst_class_kuge'),
            (assign,'$shugo_storyline_quest_array','$kuge_storyline_quest_array'),
          (else_try),
            (check_quest_active,'qst_class_ronin'),
            (assign,'$shugo_storyline_quest_array','$ronin_storyline_quest_array'),
          (try_end),
        ]
      ),
      # army upkeep
      ('weekly_army_upkeep',
        [
          (store_troop_gold,':available_cash',0),
          (call_script,'script_calculate_weekly_army_cost'),
          (assign,'$army_cost','$return'),
          (try_begin),
            (ge,':available_cash','$army_cost'),
            (troop_remove_gold,0,'$army_cost'),
            (assign,reg1,'$army_cost'),
            (display_message,'str_weekly_upkeep_1'),
          (else_try),
            (call_script,'script_determine_army_deserters'),
          (try_end),
          # also do forts
          (try_for_parties,':fort'),
            (neq,':fort',0),
            (party_get_template_id,':template',':fort'),
            (eq,':template','pt_fort'),
            (store_faction_of_party,':faction',':fort'),
            (eq,':faction','fac_player_faction'),
            (call_script,'script_calculate_weekly_army_cost',':fort'),
            (assign,':fort_cost','$return'),
            (store_mul,':asset_upkeep',1000,7),
            (val_div,':asset_upkeep',365),
            (val_mul,':asset_upkeep',360),
            (val_add,':fort_cost',':asset_upkeep'),
            (store_troop_gold,':available_cash','trp_player'),
            (try_begin),
              (ge,':available_cash',':fort_cost'),
              (troop_remove_gold,0,':fort_cost'),
            (else_try),
              (remove_party,':fort'),
              (display_message,'str_fort_lost'),
            (try_end),
          (try_end),
        ]
      ),
      ('calculate_weekly_army_cost',
        [
          (assign,':cost',0),
          (party_get_num_companion_stacks,':num_stacks','p_main_party'),
          (try_for_range,':i',0,':num_stacks'),
            (party_stack_get_troop_id,':troop_id','p_main_party',':i'),
            (neg|troop_is_hero,':troop_id'),
            (party_stack_get_size,':num_troops','p_main_party',':i'),
            (try_for_range,':unused',0,':num_troops'),
              (troop_get_slot,':troop_cost',':troop_id',slot_troop_cost),
              (val_add,':cost',':troop_cost'),
            (try_end),
          (try_end),
          (assign,'$return',':cost'),
        ]
      ),
      ('determine_army_deserters',
        [
          (party_get_num_companion_stacks,':num_stacks','p_main_party'),
          (try_for_range,':i',0,':num_stacks'),
            (party_stack_get_troop_id,':troop_id','p_main_party',':i'),
            (neg|troop_is_hero,':troop_id'),
            (party_remove_members,'p_main_party',':troop_id',1),
            (call_script,'script_calculate_weekly_army_cost'),
            (assign,':new_cost','$return'),
            (store_troop_gold,':available_cash',0),
            (try_begin),
              (lt,':available_cash',':new_cost'),
              (call_script,'script_determine_army_deserters'), # ain't recursion great!
            (else_try),
              (assign,':i',':num_stacks'), # should break out of the loop
              (troop_remove_gold,0,':new_cost'),
              (assign,reg1,':new_cost'),
              (display_message,'str_weekly_upkeep_1'),
              (display_message,'str_troops_deserted'),
            (try_end),
          (try_end),
        ]
      ),
      ('troop_transfer',
        [
          (store_script_param_1,':troop_to_transfer'),
          (store_script_param_2,':current_troop_faction'), # faction of the troop currently in the party
          (try_begin),
            (this_or_next|eq,':troop_to_transfer','trp_t2_spear_ashigaru_h'),
            (this_or_next|eq,':troop_to_transfer','trp_t2_spear_ashigaru_y'),
            (eq,':troop_to_transfer','trp_t2_spear_ashigaru_n'),
            (try_begin),
              (this_or_next|eq,':current_troop_faction','fac_hosokawa'),
              (eq,':current_troop_faction','fac_commoners'),
              (assign,':target_troop','trp_t2_spear_ashigaru_y'),
              (assign,':troop_to_return','trp_t2_spear_ashigaru_h'),
            (else_try),
              (this_or_next|eq,':current_troop_faction','fac_yamana'),
              (eq,':current_troop_faction','fac_commoners'),
              (assign,':target_troop','trp_t2_spear_ashigaru_h'),
              (assign,':troop_to_return','trp_t2_spear_ashigaru_y'),
            (try_end),
          (else_try),
            (this_or_next|eq,':troop_to_transfer','trp_samurai'),
            (this_or_next|eq,':troop_to_transfer','trp_samurai'),
            (eq,':troop_to_transfer','trp_samurai'),
            (try_begin),
              (this_or_next|eq,':current_troop_faction','fac_hosokawa'),
              (eq,':current_troop_faction','fac_commoners'),
              (assign,':target_troop','trp_samurai'),
              (assign,':troop_to_return','trp_samurai'),
            (else_try),
              (this_or_next|eq,':current_troop_faction','fac_yamana'),
              (eq,':current_troop_faction','fac_commoners'),
              (assign,':target_troop','trp_samurai'),
              (assign,':troop_to_return','trp_samurai'),
            (else_try),
              (this_or_next|eq,':troop_to_transfer','trp_t2_light_cav_h'),
              (this_or_next|eq,':troop_to_transfer','trp_t2_light_cav_y'),
              (eq,':troop_to_transfer','trp_t2_heavy_cav_n'),
              (try_begin),
                (this_or_next|eq,':current_troop_faction','fac_hosokawa'),
                (eq,':current_troop_faction','fac_commoners'),
                (assign,':target_troop','trp_t2_light_cav_y'),
                (assign,':troop_to_return','trp_t2_light_cav_h'),
              (else_try),
                (this_or_next|eq,':current_troop_faction','fac_yamana'),
                (eq,':current_troop_faction','fac_commoners'),
                (assign,':target_troop','trp_t2_light_cav_h'),
                (assign,':troop_to_return','trp_t2_light_cav_y'),
              (try_end),
              (party_count_companions_of_type,':num_troops_to_transfer','p_main_party',':troop_to_transfer'),
              (party_add_members,'p_main_party',':target_troop',':num_troops_to_transfer'),
              (party_remove_members,'p_main_party',':troop_to_transfer',':num_troops_to_transfer'),
              (party_add_members,'$g_encountered_party',':troop_to_return',':num_troops_to_transfer'),
            ],
          ),
          ('kengo_training',
            [
              (store_script_param,':weapon_type',1),
              (assign,reg20,'trp_sparring_partner'),
              (assign,reg21,'trp_skilled_sparring_partner'),
              (assign,reg22,'trp_master_sparring_partner'),
              (try_begin),
                (eq,':weapon_type',sword),
                (assign,reg30,0),
                (assign,reg15,5),
                (assign,reg16,6),
                (assign,reg17,7),
                #(assign,reg18,7),
              (else_try),
                (eq,':weapon_type',blunt_polearm),
                (assign,reg30,1),
                (assign,reg15,12),
                (assign,reg16,13),
                (assign,reg17,14),
                #(assign,reg18,15),
              (else_try),
                (eq,':weapon_type',bladed_polearm),
                (assign,reg30,2),
                (assign,reg15,8),
                (assign,reg16,9),
                (assign,reg17,10),
                #(assign,reg18,11),
              (else_try),
                (eq,':weapon_type',archery),
                (assign,reg30,3),
                (assign,reg15,16),
                (assign,reg16,17),
                (assign,reg17,18),
                #(assign,reg18,19),
              (else_try),
                (eq,':weapon_type',thrown),
                (assign,reg30,4),
                (assign,reg15,21),
                (assign,reg16,22),
                (assign,reg17,23),
                #(assign,reg18,23),
              (try_end),
              (shuffle_range,15,18),
            ]
          ),
# script_companion_training
('companion_training',
	[
		(store_script_param,':companion',1),
		(store_script_param,':sensei',2),
		(store_script_param,':option',3),
		(try_begin),
			(eq,':option',2),
			(troop_get_slot,':bit_num',':sensei',slot_sensei_flag),
			(call_script,'script_object_set_flag',obj_troop,':companion',slot_comp_training_flags,':bit_num',true),
		(else_try),
			(troop_get_slot,':bit_num',':sensei',slot_sensei_flag),
			(try_begin),
				(call_script,'script_cf_object_flag_set',obj_troop,':companion',slot_comp_training_flags,':bit_num'),
				(assign,reg0,false),
			(else_try),
				(assign,reg0,true),
			(try_end),
		(try_end),
		]
	),
		  
		# script modify special visitors
('modify_special_visitors',
	[
		(store_script_param_1,':input_party'),
		(store_script_param_2,':input_scene'),
		(try_begin),
			(eq,':input_party',south_kyoto),
			(try_begin),
				(eq,':input_scene','scn_shinden_west_hall'),
				(set_visitor,7,'trp_hosokawa_katsumoto'),
			(else_try),
				(eq,':input_scene','scn_shinden_east_hall'),
				(set_visitor,7,'trp_yamana_souzen'),
			(else_try),
				(eq,':input_scene','scn_inn'),
				(set_visitor,5,'trp_kingmaker'),
			(else_try),
				(eq,':input_scene','scn_south_kyoto_dojo'),
				(party_get_slot,':sensei',south_kyoto,slot_town_sensei),
				(troop_get_slot,':apprentice',':sensei',slot_sensei_apprentice),
				(try_begin),
					(troop_slot_neq,':apprentice',slot_troop_has_joined,1),
					(set_visitor,2,':apprentice'),
				(try_end),
				(try_begin),
					(scene_slot_eq,':input_scene',slot_dojo_sensei_away,0),
					(set_visitor,3,':sensei'),
				(try_end),
				# (try_begin),
					# (check_quest_active,'qst_companion_training'),
					# (check_quest_succeeded,'qst_companion_training'),
					# (quest_get_slot,':companion','qst_companion_training',slot_quest_companion_training_companion),
					# (set_visitor,5,':companion'),
				# (try_end),
			(try_end),
		(else_try),
			(eq,':input_party',nara),
			(try_begin),
				(eq,':input_scene','scn_inn'),
				(neg|main_party_has_troop,'trp_tsuruhiro'),
				(neg|troop_slot_eq,'trp_tsuruhiro',slot_troop_has_joined,1),
				(set_visitor,5,'trp_tsuruhiro'),
			(try_end),
		(else_try),
			(eq,':input_party',nose),
			(try_begin),
				(eq,':input_scene','scn_inn'),
				(neg|main_party_has_troop,'trp_yamamatsu'),
				(neg|troop_slot_eq,'trp_yamamatsu',slot_troop_has_joined,1),
				(set_visitor,5,'trp_yamamatsu'),
			(try_end),
		(else_try),
			(eq,':input_party',enryaku_ji),
			(try_begin),
				(eq,':input_scene','scn_temple'),
				(neg|main_party_has_troop,'trp_shinbo'),
				(neg|troop_slot_eq,'trp_shinbo',slot_troop_has_joined,1),
				(set_visitor,3,'trp_shinbo'),
			(try_end),
		(else_try),
			(eq,':input_party',itami),
			(try_begin),
				(eq,':input_scene','scn_inn'),
				(try_begin),
					(neg|main_party_has_troop,'trp_haruko'),
					(troop_slot_neq,'trp_haruko',slot_troop_has_joined,1),
					(set_visitor,5,'trp_haruko'),
				(else_try),
					(troop_slot_eq,'trp_haruko',slot_troop_at_inn,1),
					(set_visitor,5,'trp_haruko'),
				(try_end),
				(try_begin),
					(troop_slot_eq,'trp_tsuruhiro',slot_troop_at_inn,1),
					(set_visitor,6,'trp_tsuruhiro'),
				(try_end),
				(try_begin),
					(troop_slot_eq,'trp_akikane',slot_troop_at_inn,1),
					(set_visitor,7,'trp_akikane'),
				(try_end),
				(try_begin),
					(troop_slot_eq,'trp_yamamatsu',slot_troop_at_inn,1),
					(set_visitor,8,'trp_yamamatsu'),
				(try_end),
				(try_begin),
					(troop_slot_eq,'trp_shinbo',slot_troop_at_inn,1),
					(set_visitor,9,'trp_shinbo'),
				(try_end),
			(try_end),
		(else_try),
			(eq,':input_party',takashima),
			(try_begin),
				(eq,':input_scene','scn_inn'),
				(neg|main_party_has_troop,'trp_akikane'),
				(neg|troop_slot_eq,'trp_akikane',slot_troop_has_joined,1),
				(set_visitor,5,'trp_akikane'),
			(try_end),
		(else_try),
			(eq,':input_party',hyogo),
			(try_begin),
				(eq,':input_scene','scn_inn'),
				(set_visitor,5,'trp_hyogo_slaver'),
				(set_visitor,8,'trp_hyogo_disciple'),
			(try_end),
		(else_try),
			(eq,':input_party',yodo),
			(party_get_slot,':sensei',yodo,slot_town_sensei),
			(troop_get_slot,':apprentice',':sensei',slot_sensei_apprentice),
			(try_begin),
				(eq,':input_scene','scn_yodo_dojo'),
				(try_begin),
					(troop_slot_neq,':apprentice',slot_troop_has_joined,1),
					(set_visitor,2,':apprentice'),
				(try_end),
				(try_begin),
					(scene_slot_eq,':input_scene',slot_dojo_sensei_away,0),
					(set_visitor,3,':sensei'),
				(try_end),
				# (try_begin),
					# (check_quest_active,'qst_companion_training'),
					# (check_quest_succeeded,'qst_companion_training'),
					# (quest_get_slot,':companion','qst_companion_training',slot_quest_companion_training_companion),
					# (set_visitor,5,':companion'),
				# (try_end),
			(try_end),
		(else_try),
			(eq,':input_party',hikone),
			(party_get_slot,':sensei',hikone,slot_town_sensei),
			(troop_get_slot,':apprentice',':sensei',slot_sensei_apprentice),
			(try_begin),
				(eq,':input_scene','scn_hikone_dojo'),
				(try_begin),
					(troop_slot_neq,':apprentice',slot_troop_has_joined,1),
					(set_visitor,2,':apprentice'),
				(try_end),
				(try_begin),
					(scene_slot_eq,':input_scene',slot_dojo_sensei_away,0),
					(set_visitor,3,':sensei'),
				(try_end),
				# (try_begin),
					# (check_quest_active,'qst_companion_training'),
					# (check_quest_succeeded,'qst_companion_training'),
					# (quest_get_slot,':companion','qst_companion_training',slot_quest_companion_training_companion),
					# (set_visitor,5,':companion'),
				# (try_end),
			(try_end),
			(else_try),
		(eq,':input_party',haga),
			(party_get_slot,':sensei',haga,slot_town_sensei),
			(troop_get_slot,':apprentice',':sensei',slot_sensei_apprentice),
			(try_begin),
				(eq,':input_scene','scn_haga_dojo'),
				(try_begin),
					(troop_slot_neq,':apprentice',slot_troop_has_joined,1),
					(set_visitor,2,':apprentice'),
				(try_end),
				(try_begin),
					(scene_slot_eq,':input_scene',slot_dojo_sensei_away,0),
					(set_visitor,3,':sensei'),
				(try_end),
				# (try_begin),
					# (check_quest_active,'qst_companion_training'),
					# (check_quest_succeeded,'qst_companion_training'),
					# (quest_get_slot,':companion','qst_companion_training',slot_quest_companion_training_companion),
					# (set_visitor,5,':companion'),
				# (try_end),
			(try_end),
			(else_try),
		(eq,':input_party',imazu),
			(party_get_slot,':sensei',imazu,slot_town_sensei),
			(troop_get_slot,':apprentice',':sensei',slot_sensei_apprentice),
			(try_begin),
				(eq,':input_scene','scn_imazu_dojo'),
				(try_begin),
					(troop_slot_neq,':apprentice',slot_troop_has_joined,1),
					(set_visitor,2,':apprentice'),
				(try_end),
				(try_begin),
					(scene_slot_eq,':input_scene',slot_dojo_sensei_away,0),
					(set_visitor,3,':sensei'),
				(try_end),
				# (try_begin),
					# (check_quest_active,'qst_companion_training'),
					# (check_quest_succeeded,'qst_companion_training'),
					# (quest_get_slot,':companion','qst_companion_training',slot_quest_companion_training_companion),
					# (set_visitor,5,':companion'),
				# (try_end),
			(try_end),
			(else_try),
		(eq,':input_party',oya),
			(party_get_slot,':sensei',oya,slot_town_sensei),
			(troop_get_slot,':apprentice',':sensei',slot_sensei_apprentice),
			(try_begin),
				(eq,':input_scene','scn_oya_dojo'),
				(try_begin),
					(troop_slot_neq,':apprentice',slot_troop_has_joined,1),
					(set_visitor,2,':apprentice'),
				(try_end),
				(try_begin),
					(scene_slot_eq,':input_scene',slot_dojo_sensei_away,0),
					(set_visitor,3,':sensei'),
				(try_end),
				# (try_begin),
					# (check_quest_active,'qst_companion_training'),
					# (check_quest_succeeded,'qst_companion_training'),
					# (quest_get_slot,':companion','qst_companion_training',slot_quest_companion_training_companion),
					# (set_visitor,5,':companion'),
				# (try_end),
			(try_end),
		(else_try),
			(eq,':input_party',oe),
			(party_get_slot,':sensei',oe,slot_town_sensei),
			(troop_get_slot,':apprentice',':sensei',slot_sensei_apprentice),
			(try_begin),
				(eq,':input_scene','scn_oe_dojo'),
				(try_begin),
					(troop_slot_neq,':apprentice',slot_troop_has_joined,1),
					(set_visitor,2,':apprentice'),
				(try_end),
				(try_begin),
					(scene_slot_eq,':input_scene',slot_dojo_sensei_away,0),
					(set_visitor,3,':sensei'),
				(try_end),
				# (try_begin),
					# (check_quest_active,'qst_companion_training'),
					# (check_quest_succeeded,'qst_companion_training'),
					# (quest_get_slot,':companion','qst_companion_training',slot_quest_companion_training_companion),
					# (set_visitor,5,':companion'),
				# (try_end),
			(try_end),
		(else_try),
			(eq,':input_party',iga),
			(party_get_slot,':sensei',iga,slot_town_sensei),
			(troop_get_slot,':apprentice',':sensei',slot_sensei_apprentice),
			(try_begin),
				(eq,':input_scene','scn_iga_dojo'),
				(try_begin),
					(troop_slot_neq,':apprentice',slot_troop_has_joined,1),
					(set_visitor,2,':apprentice'),
				(try_end),
				(try_begin),
					(scene_slot_eq,':input_scene',slot_dojo_sensei_away,0),
					(set_visitor,3,':sensei'),
				(try_end),
				# (try_begin),
					# (check_quest_active,'qst_companion_training'),
					# (check_quest_succeeded,'qst_companion_training'),
					# (quest_get_slot,':companion','qst_companion_training',slot_quest_companion_training_companion),
					# (set_visitor,5,':companion'),
				# (try_end),
			(try_end),
		(try_end),
		]
	),
          #script modify troop stats - duelists
          ('modify_troop_stats',
            [
              (store_script_param_1,':input_troop'),
              (store_script_param_2,':weapon_type'),
              (try_begin),
                (eq,':weapon_type',1), # swords
                (troop_raise_skill,':input_troop',skl_power_strike,1),
                (troop_raise_skill,':input_troop',skl_athletics,2),
                (store_random_in_range,reg1,100,150),
                (troop_raise_proficiency,':input_troop',1,reg1),
              (else_try),
                (eq,':weapon_type',2), # bladed polearms
                (troop_raise_skill,':input_troop',skl_power_strike,1),
                (troop_raise_skill,':input_troop',skl_athletics,1),
                (store_random_in_range,reg1,100,150),
                (troop_raise_proficiency,':input_troop',2,reg1),
              (else_try),
                (eq,':weapon_type',3), # bows
                (troop_raise_skill,':input_troop',skl_power_draw,3),
                (troop_raise_skill,':input_troop',skl_athletics,1),
                (store_random_in_range,reg1,150,200),
                (troop_raise_proficiency,':input_troop',3,reg1),
              (else_try),
                (eq,':weapon_type',4), # blunt polearms
                (troop_raise_skill,':input_troop',skl_power_strike,2),
                (troop_raise_skill,':input_troop',skl_athletics,2),
                (store_random_in_range,reg1,150,200),
                (troop_raise_proficiency,':input_troop',2,reg1),
              (try_end),
          ]),
          ## initialize the garrison cost arrays
          ('init_village_garrison',
            [
              (call_script,'script_array_initialize',8),
              (assign,':garrison_cost_array','$return'),
              (call_script,'script_array_push',':garrison_cost_array','trp_veteran_defender'),
              (call_script,'script_array_push',':garrison_cost_array',360),
              (call_script,'script_array_push',':garrison_cost_array','trp_village_defender'),
              (call_script,'script_array_push',':garrison_cost_array',180),
              (call_script,'script_array_push',':garrison_cost_array','trp_villager'),
              (call_script,'script_array_push',':garrison_cost_array',15),
              (call_script,'script_array_push',':garrison_cost_array','trp_farmer'),
              (call_script,'script_array_push',':garrison_cost_array',15),
              (party_set_slot,'p_village_garrison_source',slot_garrison_cost_array,':garrison_cost_array'),
          ]),
          
          ('init_town_garrison',
            [
              (call_script,'script_array_initialize',6),
              (assign,':garrison_cost_array','$return'),
              (call_script,'script_array_push',':garrison_cost_array','trp_t2_heavy_cav_n'),
              (call_script,'script_array_push',':garrison_cost_array',720),
              (call_script,'script_array_push',':garrison_cost_array','trp_samurai'),
              (call_script,'script_array_push',':garrison_cost_array',360),
              (call_script,'script_array_push',':garrison_cost_array','trp_t2_spear_ashigaru_n'),
              (call_script,'script_array_push',':garrison_cost_array',90),
              (party_set_slot,'p_town_garrison_source',slot_garrison_cost_array,':garrison_cost_array'),
          ]),
          ('init_city_garrison',
            [
              (call_script,'script_array_initialize',8),
              (assign,':garrison_cost_array','$return'),
              (call_script,'script_array_push',':garrison_cost_array','trp_t2_heavy_cav_n'),
              (call_script,'script_array_push',':garrison_cost_array',1080),
              (call_script,'script_array_push',':garrison_cost_array','trp_t2_light_cav_n'),
              (call_script,'script_array_push',':garrison_cost_array',1080),
              (call_script,'script_array_push',':garrison_cost_array','trp_samurai'),
              (call_script,'script_array_push',':garrison_cost_array',360),
              (call_script,'script_array_push',':garrison_cost_array','trp_t2_spear_ashigaru_n'),
              (call_script,'script_array_push',':garrison_cost_array',90),
              (party_set_slot,'p_city_garrison_source',slot_garrison_cost_array,':garrison_cost_array'),
          ]),
          
          ('init_garrison_troop_levels',
            [
              (party_add_members,'p_village_garrison_source','trp_veteran_defender',10),
              (party_add_members,'p_village_garrison_source','trp_village_defender',10),
              (party_add_members,'p_village_garrison_source','trp_villager',10),
              (party_add_members,'p_village_garrison_source','trp_farmer',10),
              (party_add_members,'p_town_garrison_source','trp_t2_heavy_cav_n',10),
              (party_add_members,'p_town_garrison_source','trp_samurai',10),
              (party_add_members,'p_town_garrison_source','trp_t2_spear_ashigaru_n',10),
              (party_add_members,'p_city_garrison_source','trp_t2_heavy_cav_n',10),
              (party_add_members,'p_city_garrison_source','trp_t2_light_cav_n',10),
              (party_add_members,'p_city_garrison_source','trp_samurai',10),
              (party_add_members,'p_city_garrison_source','trp_t2_bow_ashigaru_n',10),
          ]),
          ('update_garrison',
            [
              (store_script_param,':input_town',1),
              (party_get_slot,':garrison_source_party',':input_town',slot_town_garrison_source),
              (party_get_slot,':garrison_cost_array',':garrison_source_party',slot_garrison_cost_array),
              (call_script,'script_array_copy',':garrison_cost_array'),
              (assign,':garrison_cost_array','$return'),
              (party_get_slot,':len_cost_array',':garrison_cost_array',array_value_length),
              (party_get_slot,':available_cash',':input_town',slot_town_treasury),
              (party_get_num_companions,':garrison_size',':input_town'),
              (try_begin),   #first check if garrison is bigger than 100
                (lt,':garrison_size',100),
                (store_div,':length',':len_cost_array',2),
                (try_for_range,':unused',0,':length'),
                  (call_script,'script_array_cycle',':garrison_cost_array'),
                  (assign,':troop_id','$return'),
                  (call_script,'script_array_cycle',':garrison_cost_array'),
                  (assign,':troop_cost','$return'),
                  (try_begin),
                    (eq,':input_town',yodo),
                    (assign,reg51,':available_cash'),
                    (assign,reg52,':troop_cost'),
                    (str_store_troop_name,s51,':troop_id'),
                    #(display_message,'str_debug_garrison'),
                  (try_end),
                  (ge,':available_cash',':troop_cost'),
                  (party_count_companions_of_type,':stock',':garrison_source_party',':troop_id'),
                  (ge,':stock',1),
                  (party_add_members,':input_town',':troop_id',1),
                  (party_remove_members,':garrison_source_party',':troop_id',1),
				  (call_script,'script_object_modify_slot',obj_party,':input_town',slot_town_treasury,op_sub,':troop_cost'),
                  #(assign,':i',':length'),
                (try_end),
              (try_end),
              (remove_party,':garrison_cost_array'),
            ]
          ),
          ('messenger',
            [
              (store_script_param_1,':input_party'),
              (store_script_param_2,':input_town'),
              (party_get_slot,':input_array',':input_party',slot_spawn_array),
              (call_script,'script_array_queue',':input_array'),
              (assign,':input_script','$return'),
              (call_script,'script_array_queue',':input_array'),
              (assign,':input_value','$return'),
              (call_script,':input_script',':input_value'),
              (call_script,'script_array_push',':input_array','script_modify_faction_attitude'),
              (store_faction_of_party,reg1,':input_town'),
              (faction_get_slot,reg2,reg1,slot_faction_att_to_player),
              (call_script,'script_array_push',':input_array',reg2),
              (party_set_slot,':input_party',slot_spawn_array,':input_array'),
              (party_get_slot,':input_array2',':input_town',slot_town_dest_array), # need to set this up
              (call_script,'script_array_queue',':input_array2'),
              (call_script,'script_array_push',':input_array2','$return'),
              (party_set_ai_behavior,':input_party',ai_bhvr_travel_to_party),
              (party_set_ai_object,':input_party','$return'),
          ]),
# script check city status - sets the faction possession bits
('check_city_status',
	[
		(store_script_param_1,':faction'),
		(try_for_range,':city','p_city_5','p_town_1'),
			(party_get_slot,':init_fac',':city',slot_town_initial_faction),
			(call_script,'script_cf_faction_is_ally_of_faction',':faction',':init_fac'),
			(store_faction_of_party,':curr_fac',':city'),
			(neq,':init_fac',':curr_fac'),
			(faction_get_slot,':flags',':faction',slot_faction_possession_flags),
			(call_script,'script_set_flag_bit',':flags',3,1),
			(faction_set_slot,':faction',slot_faction_possession_flags,reg0),
		(try_end),
		(try_for_range,':town','p_town_1','p_village_1'),
			(party_get_slot,':init_fac',':town',slot_town_initial_faction),
			(call_script,'script_cf_faction_is_ally_of_faction',':faction',':init_fac'),
			(store_faction_of_party,':curr_fac',':town'),
			(neq,':init_fac',':curr_fac'),
			(faction_get_slot,':flags',':faction',slot_faction_possession_flags),
			(call_script,'script_set_flag_bit',':flags',2,1),
			(faction_set_slot,':faction',slot_faction_possession_flags,reg0),
		(try_end),
		(try_for_range,':village','p_village_1','p_village_38'),
			(party_get_slot,':init_fac',':village',slot_town_initial_faction),
			(call_script,'script_cf_faction_is_ally_of_faction',':faction',':init_fac'),
			(store_faction_of_party,':curr_fac',':village'),
			(neq,':init_fac',':curr_fac'),
			(faction_get_slot,':flags',':faction',slot_faction_possession_flags),
			(call_script,'script_set_flag_bit',':flags',1,1),
			(faction_set_slot,':faction',slot_faction_possession_flags,reg0),
		(try_end),
		]
	),
# calculates daily faction spawn points based on current faction strength
          ('calculate_faction_spawn_points',
            [
              (store_script_param_1,':faction'),
              (faction_get_slot,':spawn_points',':faction',slot_faction_strength),
              # (store_div,':spawn_points',':score',10),
              (call_script,'script_object_modify_slot',obj_faction,':faction',slot_faction_spawn_points,op_add,':spawn_points'),
			  (str_store_faction_name,s10,':faction'),
			  (assign,reg10,':spawn_points'),
			  (display_message,'@{s10} gets {reg10} spawn points.',debug_text),
            ]
          ),
          ('modify_faction_treasury',
            [
              (store_script_param_1,':faction'),
              (store_script_param_2,':value'),
              (faction_get_slot,':available_cash',':faction',slot_faction_treasury),
              (val_add,':available_cash',':value'),
              (faction_set_slot,':faction',slot_faction_treasury,':available_cash'),
            ]
          ),
          # checks if the two factions are allies
          ('cf_faction_is_ally_of_faction',
            [
              (store_script_param_1,':fac1'),
              (store_script_param_2,':fac2'),
              (store_relation,':rel',':fac1',':fac2'),
              (try_begin),
                (eq,':fac1',':fac2'),
                (assign,':ally',1),
              (else_try),
                (ge,':rel',0),
                (assign,':ally',1),
              (else_try),
                (assign,':ally',0),
              (try_end),
              (eq,':ally',1),
            ]
          ),
		  
		('builders',
            [
              (try_for_parties,':builder'),
                (party_get_template_id,':template',':builder'),
                (eq,':template','pt_builder'),
                (get_party_ai_object,':ai_obj',':builder'),
                (neq,':ai_obj','p_main_party'),
                (party_get_slot,':dest',':builder',slot_spawn_dest),
                (party_get_slot,':origin',':builder',slot_spawn_origin),
                (store_distance_to_party_from_party,':d1',':origin',':dest'),
                (store_distance_to_party_from_party,':d2',':builder',':origin'),
                (val_mul,':d2',100), # d2 will be less than d1, trigger on >= 60
                (val_div,':d2',':d1'),
                (ge,':d2',60),
                (set_spawn_radius,0),
                (spawn_around_party,':builder','pt_fort'),
                (call_script,'script_party_add_party',reg0,':builder'),
                (party_get_slot,':attitude',':builder',slot_spawn_att_to_player),
                (party_set_slot,reg0,slot_spawn_att_to_player,':attitude'),
                (party_get_slot,':cash',':builder',slot_spawn_gold),
                (store_faction_of_party,':faction',':builder'),
                (remove_party,':builder'),
                (party_set_faction,':builder',':faction'),
                (party_set_slot,reg0,slot_castle_progress,0),
                (party_set_slot,reg0,slot_castle_treasury,':cash'),
              (try_end),
            ]
          ),
('initialize_classes',
	[
		(assign,'$ptr_bushi_storyline_quest_array',0),
		(assign,'$ptr_kuge_storyline_quest_array',0),
		(assign,'$ptr_ronin_storyline_quest_array',0),
		(assign,'$ptr_merchant_storyline_quest_array',0),
		(call_script,'script_array_initialize',5),
		(assign,'$g_kuge_rank_array','$return'),
		(call_script,'script_class_set_rank','$g_kuge_rank_array',class_kuge,1,3600,42,1000,'str_kuge_rank_1'),
		(call_script,'script_class_set_rank','$g_kuge_rank_array',class_kuge,2,8100,60,2150,'str_kuge_rank_2'),
		(call_script,'script_class_set_rank','$g_kuge_rank_array',class_kuge,3,13725,78,6000,'str_kuge_rank_3'),
		(call_script,'script_class_set_rank','$g_kuge_rank_array',class_kuge,4,20750,90,11000,'str_kuge_rank_4'),
		(call_script,'script_class_set_rank','$g_kuge_rank_array',class_kuge,5,29454,105,15000,'str_kuge_rank_5'),
		(call_script,'script_class_set_rank','$g_kuge_rank_array',class_kuge,5,45831,130,null,'str_kuge_rank_6'),
		(call_script,'script_array_initialize',14),
		(assign,'$g_bushi_rank_array','$return'),
		(call_script,'script_class_set_rank','$g_bushi_rank_array',class_bushi,0,360,0,50,'str_bushi_rank_1'),
		(call_script,'script_class_set_rank','$g_bushi_rank_array',class_bushi,1,690,6,100,'str_bushi_rank_2'),
		(call_script,'script_class_set_rank','$g_bushi_rank_array',class_bushi,2,1040,9,440,'str_bushi_rank_3'),
		(call_script,'script_class_set_rank','$g_bushi_rank_array',class_bushi,3,1730,12,1020,'str_bushi_rank_4'),
		(call_script,'script_class_set_rank','$g_bushi_rank_array',class_bushi,4,3120,15,1860,'str_bushi_rank_5'),
		(call_script,'script_class_set_rank','$g_bushi_rank_array',class_bushi,5,4500,18,2960,'str_bushi_rank_6'),
		(call_script,'script_class_set_rank','$g_bushi_rank_array',class_bushi,6,5540,21,4330,'str_bushi_rank_7'),
		(call_script,'script_class_set_rank','$g_bushi_rank_array',class_bushi,7,6920,24,5970,'str_bushi_rank_8'),
		(call_script,'script_class_set_rank','$g_bushi_rank_array',class_bushi,8,10380,27,7880,'str_bushi_rank_9'),
		(call_script,'script_class_set_rank','$g_bushi_rank_array',class_bushi,9,17310,30,10060,'str_bushi_rank_10'),
		(call_script,'script_class_set_rank','$g_bushi_rank_array',class_bushi,10,27690,33,12530,'str_bushi_rank_11'),
		(call_script,'script_class_set_rank','$g_bushi_rank_array',class_bushi,11,48460,36,15280,'str_bushi_rank_12'),
		(call_script,'script_class_set_rank','$g_bushi_rank_array',class_bushi,12,58850,39,18310,'str_bushi_rank_13'),
		(call_script,'script_class_set_rank','$g_bushi_rank_array',class_bushi,13,69230,42,null,'str_bushi_rank_14'),
		]
	),
          ##############################################################taxes
          ('collect_taxes',
            [
              (store_script_param_1,':input_town'),
              (store_script_param_2,':tax_collector'),
              (party_get_slot,':town_size',':input_town',slot_town_size),
              (try_begin),
                (eq,':town_size',ct_small_village),
                (assign,':tax_rate',360),
              (else_try),
                (eq,':town_size',ct_village),
                (assign,':tax_rate',720),
              (else_try),
                (eq,':town_size',ct_large_village),
                (assign,':tax_rate',1440),
              (else_try),
                (eq,':town_size',ct_town),
                (assign,':tax_rate',14400),
              (else_try),
                (eq,':town_size',ct_large_town),
                (assign,':tax_rate',28800),
              (else_try),
                (eq,':town_size',ct_port),
                (assign,':tax_rate',36000),
              (else_try),
                (eq,':town_size',ct_city),
                (assign,':tax_rate',360000),
              (try_end),
              (party_get_slot,':available_cash',':input_town',slot_town_treasury),
              (try_begin),
                (ge,':available_cash',':tax_rate'),
                (call_script,'script_object_modify_slot',obj_party,':input_town',slot_town_treasury,op_sub,':tax_rate'),
				(call_script,'script_object_modify_slot',obj_party,':tax_collector',slot_spawn_gold,op_add,':tax_rate'),
              (else_try),
                (lt,':available_cash',':tax_rate'),
                (call_script,'script_object_modify_slot',obj_party,':input_town',slot_town_treasury,op_sub,':available_cash'),
				(call_script,'script_object_modify_slot',obj_party,':tax_collector',slot_spawn_gold,op_add,':available_cash'),
				(call_script,'script_object_modify_slot',obj_party,':input_town',slot_town_unrest,op_add,1),
              (try_end),
            ]
          ),
          ('check_city_under_siege',
            [
              (assign,':under_siege',0),
              (try_for_parties,':attacker'),
                (store_faction_of_party,':attacker_faction',':attacker'),
                (party_is_in_any_town,':attacker'),
                (get_party_ai_object,':defender',':attacker'),
                (store_faction_of_party,':defender_faction',':defender'),
                (call_script,'script_cf_faction_enemies',':attacker_faction',':defender_faction'),
                (eq,reg0,1),
                (assign,':under_siege',1),
              (try_end),
              (try_begin),
                (eq,':under_siege',1),
                (party_set_slot,':defender',slot_town_under_siege,1),
              (else_try),
                (party_set_slot,':defender',slot_town_under_siege,0),
              (try_end),
            ]
          ),
		  
		('cf_faction_enemies',
            [
              (store_script_param_1,':fac1'),
              (store_script_param_2,':fac2'),
              (store_relation,':relations',':fac1',':fac2'),
              (try_begin),
                (lt,':relations',0),
                (assign,reg0,1),
              (else_try),
                (assign,reg0,0),
              (try_end),
              (eq,reg0,1),
            ]
          ),
          ('city_taken',
            [
              (store_script_param_1,':fallen_city'),
              (store_script_param_2,':besieger'),
              (party_get_slot,':orders',':besieger',slot_spawn_orders),
              (try_begin),
                (eq,':orders',orders_capture),
                (store_faction_of_party,':city_fac',':fallen_city'),
                (store_faction_of_party,':besieger_fac',':besieger'),
                (party_set_faction,':fallen_city',':besieger_fac'),
                (store_faction_of_party,':new_city_fac',':fallen_city'),
                (str_store_faction_name,1,':city_fac'),
                (str_store_faction_name,2,':new_city_fac'),
                (party_set_slot,':fallen_city',slot_town_under_siege,0),
                (party_set_slot,':fallen_city',slot_town_siege_attacker,-1),
                (call_script,'script_party_add_party',':fallen_city',':besieger'),
                (party_clear,':besieger'),
                (remove_party,':besieger'),
              (else_try),
                (eq,':orders',orders_raid),
                (party_get_slot,':available_cash',':fallen_city',slot_town_treasury),
                (party_set_slot,':fallen_city',slot_town_treasury,0),
                (store_faction_of_party,':faction',':besieger'),
                (val_mul,':available_cash',10),
                (call_script,'script_object_modify_slot',obj_faction,':faction',slot_faction_spawn_points,op_add,':available_cash'),
                (party_clear,':besieger'),
                (remove_party,':besieger'),
              (try_end),
            ]
          ),
          
          ###################### Debug scripts
          ('debug_relations_and_attitude',
            [
              (store_script_param_1,':town'),
              (store_faction_of_party,':faction',':town'),
              (try_begin),
                (party_slot_eq,':town',slot_town_patrol_active,1),
                (party_get_slot,reg13,':town',slot_town_patrol),
              (else_try),
                (neg|party_slot_eq,':town',slot_town_patrol_active,1),
                (assign,':patrol',-1),
              (try_end),
              (str_store_party_name,1,':town'),
              (str_store_faction_name,2,':faction'),
              (party_get_slot,reg11,':town',slot_town_att_to_player),
              (faction_get_slot,reg12,':faction',slot_faction_att_to_player),
              (try_begin),
                (neq,':patrol',-1),
                (party_get_slot,reg14,':patrol',slot_spawn_att_to_player),
              (else_try),
                (eq,':patrol',-1),
                (assign,reg14,-1),
              (try_end),
              (store_relation,reg10,':faction','fac_player_faction'),
			  ]
			  ),
              #(display_message,'str_debug_relations'),
## battle mini map scripts
("map_get_scale",
	[
		(init_position,pos1),
		(position_set_x,pos1,10),
		(position_set_y,pos1,10),
		(assign,"$distance_x",10),
		(assign,"$distance_y",10),
		(call_script,"script_map_scale_near_x"),
		(call_script,"script_map_scale_near_y"),
		]
	),
("map_scale_near_x",
	[
		(val_add,"$distance_x",1000),
		(position_move_x,pos1,1000),
		(position_set_z_to_ground_level,pos1),
		(position_get_z,reg1,pos1),
		(try_begin),
			(eq,reg1,10000),
		(else_try),
			(call_script,"script_map_scale_near_x"),
		(try_end),
	]),
("map_scale_near_y",
	[
		(val_add,"$distance_y",1000),
		(position_move_y,pos1,1000),
		(position_set_z_to_ground_level,pos1),
		(position_get_z,reg1,pos1),
		(try_begin),
			(eq,reg1,10000),
		(else_try),
			(call_script,"script_map_scale_near_y"),
		(try_end),
	]),
("create_relief_map",
	[
		# (try_begin),
			# (eq,"$map_detail",0),
			# (assign,"$map_detail",50),
		# (try_end),
		# (assign,":sum",0),
		# (call_script,"script_map_get_scale"),
		# (set_fixed_point_multiplier, 1000),
		# (store_div,":part_width","$g_battle_map_width","$map_detail"),
		# (store_div,":part_height","$g_battle_map_height","$map_detail"),
		# (try_for_range,":pos_y",0,"$map_detail"),
			# (try_for_range,":pos_x",0,"$map_detail"),
				# (init_position,pos3),
				# (store_div,':factor',"$distance_x","$map_detail"),
				# (store_mul,":real_map_x",':factor',":pos_x"),
				# (store_div,':factor',"$distance_y","$map_detail"),
				# (store_mul,":real_map_y",':factor',":pos_y"),
				# (position_set_x,pos3,":real_map_x"),
				# (position_set_y,pos3,":real_map_y"),
				# (position_set_z,pos3, 10000),
				# (position_set_z_to_ground_level,pos3),
				# (position_get_z, ":cur_pos_z",pos3),
				# (create_mesh_overlay,':pixel',"mesh_white_plane"),
				# (try_begin),
					# (le,":cur_pos_z",-1500),
					# (overlay_set_color,':pixel',blue3),
				# (else_try),
					# (is_between,":cur_pos_z",-1499,-500),
					# (overlay_set_color,':pixel',blue2),
				# (else_try),
					# (is_between,":cur_pos_z",-499,0),
					# (overlay_set_color,':pixel',blue1),
				# (else_try),
					# (is_between,":cur_pos_z",1,1000),
					# (overlay_set_color,':pixel',green1),
				# (else_try),
					# (is_between,":cur_pos_z",1001,2000),
					# (overlay_set_color,':pixel',green2),
				# (else_try),
					# (is_between,":cur_pos_z",2001,3500),
					# (overlay_set_color,':pixel',green3),
				# (else_try),
					# (is_between,":cur_pos_z",3501,5000),
					# (overlay_set_color,':pixel',green4),
				# (else_try),
					# (is_between,":cur_pos_z",5001,7000),
					# (overlay_set_color,':pixel',green5),
				# (else_try),
					# (is_between,":cur_pos_z",7001,9000),
					# (overlay_set_color,':pixel',brown1),
				# (else_try),
					# (is_between,":cur_pos_z",9001,12000),
					# (overlay_set_color,':pixel',brown2),
				# (else_try),
					# (is_between,":cur_pos_z",12001,15000),
					# (overlay_set_color,':pixel',brown3),
				# (else_try),
					# (is_between,":cur_pos_z",15001,19000),
					# (overlay_set_color,':pixel',brown4),
				# (else_try),
					# (is_between,":cur_pos_z",19001,25000),
					# (overlay_set_color,':pixel',brown5),
				# (else_try),
					# (is_between,":cur_pos_z",25001,30000),
					# (overlay_set_color,':pixel',brown6),
				# (else_try),
					# (is_between,":cur_pos_z",30001,35000),
					# (overlay_set_color,':pixel',brown7),
				# (else_try),
					# (is_between,":cur_pos_z",35001,40000),
					# (overlay_set_color,':pixel',brown8),
				# (else_try),
					# (overlay_set_color,':pixel',black),
				# (try_end),
				# (init_position,pos2),
				# (store_mul,':pizel_x_width',50,":part_width"),
				# (position_set_x,pos2,':pizel_x_width'),
				# (store_mul,':pixel_y_width',50,":part_height"),
				# (position_set_y,pos2,':pixel_y_width'),
				# (overlay_set_size,':pixel',pos2),
				# (store_sub,':y_detail',"$map_detail",":pos_y"),
				# (store_mul,':pixel_y_pos',':y_detail',"$g_battle_map_height"),
				# (val_div,':pixel_y_pos',"$map_detail"),
				# (store_sub,':x_detail',"$map_detail",":pos_x"),
				# (store_mul,':pixel_x_pos',':x_detail',"$g_battle_map_width"),
				# (val_div,':pixel_x_pos',"$map_detail"),
				# (store_sub,':final_pixel_y_pos',730,':pixel_y_pos'),
				# (store_sub,':final_pixel_x_pos',980,':pixel_x_pos'),
				# (position_set_x,pos2,':final_pixel_x_pos'),
				# (position_set_y,pos2,':final_pixel_y_pos'),
				# (position_set_z,pos2,-1),
				# (overlay_set_position,':pixel',pos2),
				# (val_add,":sum",":cur_pos_z"),
				# (overlay_set_alpha,':pixel',0x00),
			# (try_end),
		# (try_end),
		# (val_div,":sum",10000),
		# (assign,reg1,":sum"),
		# (display_message,"str_reg1"),
	]
),
############### AGENT SCRIPTS
('agent_get_level',
	[
		(store_script_param,':agent_no',1),
		(agent_get_troop_id,':troop_id',':agent_no'),
		(store_character_level,reg0,':troop_id'),
		]
	),
('agent_get_skill_level',
	[
		(store_script_param,':agent_no',1),
		(store_script_param,':skill',2),
		(agent_get_troop_id,':troop_id',':agent_no'),
		(store_skill_level,reg0,':skill',':troop_id'),
		]
	),
('cf_agent_check_morale',
	[
		(store_script_param,':team_morale',1),
		(assign,':chance_to_run',5),
		(store_div,':modifier',':team_morale',5),
		(store_sub,':modifier',16,':modifier'),
		(val_add,':chance_to_run',':modifier'),
		(store_random_in_range,':roll',0,100),
		(lt,':roll',':chance_to_run'),
		]
	),
('cf_agent_check_rout',
	[
		(store_script_param,':agent_no',1),
		(agent_get_party_id,':agent_party',':agent_no'),
		(store_agent_hit_points,':agent_hp',':agent_no'),
		(store_mul,':chance_to_run',':agent_hp',50),
		(val_div,':chance_to_run',100),
		(call_script,'script_agent_get_level',':agent_no'),
		(assign,':agent_level',reg0),
		(val_div,':agent_level',10),
		(val_add,':chance_to_run',':agent_level'),
		(assign,':leadership',0),
		(try_begin),
			(eq,':agent_party','p_main_party'),
			(store_skill_level,':leadership',skl_leadership,'trp_player'),
			(val_mul,':leadership',2),
		(try_end),
		(val_add,':chance_to_run',':leadership'),
		(store_sub,':chance_to_run',100,':chance_to_run'),
		(store_random_in_range,':roll',0,100),
		(lt,':roll',':chance_to_run'),
		]
	),
]

debug = """

    (call_script, "script_update_party_creation_random_limits"),
	# Reseting player party icon
	(assign, "$g_player_party_icon", -1),
	# Setting food bonuses
	(item_set_slot, "itm_smoked_fish", slot_item_food_bonus, 3),
	(item_set_slot, "itm_dried_meat", slot_item_food_bonus, 4),
	(item_set_slot, "itm_pork", slot_item_food_bonus, 4),
	(item_set_slot, "itm_bread", slot_item_food_bonus, 2),
	(item_set_slot, "itm_apples", slot_item_food_bonus, 2),
	(item_set_slot, "itm_cheese", slot_item_food_bonus, 3),
	(item_set_slot, "itm_chicken", slot_item_food_bonus, 3),
	(item_set_slot, "itm_honey", slot_item_food_bonus, 5),
	(item_set_slot, "itm_cabbages", slot_item_food_bonus, 1),
	(item_set_slot, "itm_sausages", slot_item_food_bonus, 4),
	(item_set_slot, "itm_butter", slot_item_food_bonus, 5),

	(item_set_slot, "itm_wine", slot_item_food_bonus, 4),
	(item_set_slot, "itm_ale", slot_item_food_bonus, 3),

	# Setting the random town sequence:
	(store_sub, ":num_towns", towns_end, towns_begin),
	(assign, ":num_iterations", ":num_towns"),
	(try_for_range, ":cur_town_no", 0, ":num_towns"),
	  (troop_set_slot, "trp_random_town_sequence", ":cur_town_no", -1),
	(try_end),
	(assign, ":cur_town_no", 0),
	(try_for_range, ":unused", 0, ":num_iterations"),
	  (store_random_in_range, ":random_no", 0, ":num_towns"),
	  (assign, ":is_unique", 1),
	  (try_for_range, ":cur_town_no_2", 0, ":num_towns"),
	    (troop_slot_eq, "trp_random_town_sequence", ":cur_town_no_2", ":random_no"),
	    (assign, ":is_unique", 0),
	  (try_end),
	  (try_begin),
	    (eq, ":is_unique", 1),
	    (troop_set_slot, "trp_random_town_sequence", ":cur_town_no", ":random_no"),
	    (val_add, ":cur_town_no", 1),
	  (else_try),
	    (val_add, ":num_iterations", 1),
	  (try_end),
	(try_end),
	# Cultures:
	(faction_set_slot, "fac_culture_1",  slot_faction_tier_1_troop, "trp_swadian_recruit"),
	(faction_set_slot, "fac_culture_1",  slot_faction_tier_2_troop, "trp_swadian_militia"),
	(faction_set_slot, "fac_culture_1",  slot_faction_tier_3_troop, "trp_swadian_footman"),
	(faction_set_slot, "fac_culture_1",  slot_faction_tier_4_troop, "trp_swadian_infantry"),
	(faction_set_slot, "fac_culture_1",  slot_faction_tier_5_troop, "trp_swadian_knight"),


	(faction_set_slot, "fac_culture_2", slot_faction_tier_1_troop, "trp_vaegir_recruit"),
	(faction_set_slot, "fac_culture_2", slot_faction_tier_2_troop, "trp_vaegir_footman"),
	(faction_set_slot, "fac_culture_2", slot_faction_tier_3_troop, "trp_vaegir_veteran"),
	(faction_set_slot, "fac_culture_2", slot_faction_tier_4_troop, "trp_vaegir_infantry"),
	(faction_set_slot, "fac_culture_2", slot_faction_tier_5_troop, "trp_vaegir_knight"),

	(faction_set_slot, "fac_culture_3", slot_faction_tier_1_troop, "trp_khergit_tribesman"),
	(faction_set_slot, "fac_culture_3", slot_faction_tier_2_troop, "trp_khergit_skirmisher"),
	(faction_set_slot, "fac_culture_3", slot_faction_tier_3_troop, "trp_khergit_horseman"),
	(faction_set_slot, "fac_culture_3", slot_faction_tier_4_troop, "trp_khergit_horse_archer"),
	(faction_set_slot, "fac_culture_3", slot_faction_tier_5_troop, "trp_khergit_veteran_horse_archer"),

	(faction_set_slot, "fac_culture_4", slot_faction_tier_1_troop, "trp_nord_recruit"),
	(faction_set_slot, "fac_culture_4", slot_faction_tier_2_troop, "trp_nord_footman"),
	(faction_set_slot, "fac_culture_4", slot_faction_tier_3_troop, "trp_nord_trained_footman"),
	(faction_set_slot, "fac_culture_4", slot_faction_tier_4_troop, "trp_nord_warrior"),
	(faction_set_slot, "fac_culture_4", slot_faction_tier_5_troop, "trp_nord_veteran"),

	(faction_set_slot, "fac_culture_5", slot_faction_tier_1_troop, "trp_rhodok_tribesman"),
	(faction_set_slot, "fac_culture_5", slot_faction_tier_2_troop, "trp_rhodok_spearman"),
	(faction_set_slot, "fac_culture_5", slot_faction_tier_3_troop, "trp_rhodok_trained_spearman"),
	(faction_set_slot, "fac_culture_5", slot_faction_tier_4_troop, "trp_rhodok_veteran_spearman"),
	(faction_set_slot, "fac_culture_5", slot_faction_tier_5_troop, "trp_rhodok_sergeant"),

	# Factions:
	(faction_set_slot, "fac_kingdom_1",  slot_faction_culture, "fac_culture_1"),
	(faction_set_slot, "fac_kingdom_1",  slot_faction_leader, "trp_kingdom_1_lord"),

	(faction_set_slot, "fac_kingdom_2",  slot_faction_culture, "fac_culture_2"),
	(faction_set_slot, "fac_kingdom_2",  slot_faction_leader, "trp_kingdom_2_lord"),

	(faction_set_slot, "fac_kingdom_3",  slot_faction_culture, "fac_culture_3"),
	(faction_set_slot, "fac_kingdom_3",  slot_faction_leader, "trp_kingdom_3_lord"),

	(faction_set_slot, "fac_kingdom_4",  slot_faction_culture, "fac_culture_4"),
	(faction_set_slot, "fac_kingdom_4",  slot_faction_leader, "trp_kingdom_4_lord"),

	(faction_set_slot, "fac_kingdom_5",  slot_faction_culture, "fac_culture_5"),
	(faction_set_slot, "fac_kingdom_5",  slot_faction_leader, "trp_kingdom_5_lord"),

	(call_script, "script_diplomacy_start_war_between_kingdoms", "fac_kingdom_1", "fac_kingdom_2"),
	(call_script, "script_diplomacy_start_war_between_kingdoms", "fac_kingdom_1", "fac_kingdom_5"),
	(call_script, "script_diplomacy_start_war_between_kingdoms", "fac_kingdom_4", "fac_kingdom_2"),
	(call_script, "script_diplomacy_start_war_between_kingdoms", "fac_kingdom_4", "fac_kingdom_1"),
	(call_script, "script_diplomacy_start_war_between_kingdoms", "fac_kingdom_3", "fac_kingdom_2"),
	(call_script, "script_diplomacy_start_war_between_kingdoms", "fac_kingdom_3", "fac_kingdom_5"),

	(try_for_range, ":faction_no", factions_begin, factions_end),
	  (faction_get_slot, ":culture", ":faction_no", slot_faction_culture),
	  
	  (faction_get_slot, ":troop", ":culture",  slot_faction_tier_1_troop),
	  (faction_set_slot, ":faction_no",  slot_faction_tier_1_troop, ":troop"),
	  (faction_get_slot, ":troop", ":culture",  slot_faction_tier_2_troop),
	  (faction_set_slot, ":faction_no",  slot_faction_tier_2_troop, ":troop"),
	  (faction_get_slot, ":troop", ":culture",  slot_faction_tier_3_troop),
	  (faction_set_slot, ":faction_no",  slot_faction_tier_3_troop, ":troop"),
	  (faction_get_slot, ":troop", ":culture",  slot_faction_tier_4_troop),
	  (faction_set_slot, ":faction_no",  slot_faction_tier_4_troop, ":troop"),
	  (faction_get_slot, ":troop", ":culture",  slot_faction_tier_5_troop),
	  (faction_set_slot, ":faction_no",  slot_faction_tier_5_troop, ":troop"),
	  
	  (try_begin),
	    (faction_slot_eq, ":faction_no", slot_faction_culture, "fac_culture_1"),
	    
	    (faction_set_slot, ":faction_no",  slot_faction_deserter_troop, "trp_swadian_deserter"),
	    (faction_set_slot, ":faction_no",  slot_faction_guard_troop, "trp_swadian_sergeant"),
	    (faction_set_slot, ":faction_no",  slot_faction_messenger_troop, "trp_swadian_messenger"),
	    (faction_set_slot, ":faction_no",  slot_faction_prison_guard_troop, "trp_swadian_prison_guard"),
	    (faction_set_slot, ":faction_no",  slot_faction_castle_guard_troop, "trp_swadian_castle_guard"),
	    (faction_set_slot, ":faction_no",  slot_faction_reinforcements_a, "pt_kingdom_1_reinforcements_a"),
	    (faction_set_slot, ":faction_no",  slot_faction_reinforcements_b, "pt_kingdom_1_reinforcements_b"),
	    (faction_set_slot, ":faction_no",  slot_faction_reinforcements_c, "pt_kingdom_1_reinforcements_c"),
	  (else_try),
	    (faction_slot_eq, ":faction_no", slot_faction_culture, "fac_culture_2"),
	    
	    (faction_set_slot, ":faction_no", slot_faction_deserter_troop, "trp_vaegir_deserter"),
	    (faction_set_slot, ":faction_no", slot_faction_guard_troop, "trp_vaegir_guard"),
	    (faction_set_slot, ":faction_no", slot_faction_messenger_troop, "trp_vaegir_messenger"),
	    (faction_set_slot, ":faction_no", slot_faction_prison_guard_troop, "trp_vaegir_prison_guard"),
	    (faction_set_slot, ":faction_no", slot_faction_castle_guard_troop, "trp_vaegir_castle_guard"),
	    (faction_set_slot, ":faction_no",  slot_faction_reinforcements_a, "pt_kingdom_2_reinforcements_a"),
	    (faction_set_slot, ":faction_no",  slot_faction_reinforcements_b, "pt_kingdom_2_reinforcements_b"),
	    (faction_set_slot, ":faction_no",  slot_faction_reinforcements_c, "pt_kingdom_2_reinforcements_c"),
	  (else_try),
	    (faction_slot_eq, ":faction_no", slot_faction_culture, "fac_culture_3"),
	    
	    (faction_set_slot, ":faction_no", slot_faction_deserter_troop, "trp_khergit_deserter"),
	    (faction_set_slot, ":faction_no", slot_faction_guard_troop, "trp_khergit_horseman"),
	    (faction_set_slot, ":faction_no", slot_faction_messenger_troop, "trp_khergit_messenger"),
	    (faction_set_slot, ":faction_no", slot_faction_prison_guard_troop, "trp_khergit_prison_guard"),
	    (faction_set_slot, ":faction_no", slot_faction_castle_guard_troop, "trp_khergit_castle_guard"),
	    (faction_set_slot, ":faction_no",  slot_faction_reinforcements_a, "pt_kingdom_3_reinforcements_a"),
	    (faction_set_slot, ":faction_no",  slot_faction_reinforcements_b, "pt_kingdom_3_reinforcements_b"),
	    (faction_set_slot, ":faction_no",  slot_faction_reinforcements_c, "pt_kingdom_3_reinforcements_c"),
	  (else_try),
	    (faction_slot_eq, ":faction_no", slot_faction_culture, "fac_culture_4"),
	    
	    (faction_set_slot, ":faction_no", slot_faction_deserter_troop, "trp_nord_deserter"),
	    (faction_set_slot, ":faction_no", slot_faction_guard_troop, "trp_nord_warrior"),
	    (faction_set_slot, ":faction_no", slot_faction_messenger_troop, "trp_nord_messenger"),
	    (faction_set_slot, ":faction_no", slot_faction_prison_guard_troop, "trp_nord_prison_guard"),
	    (faction_set_slot, ":faction_no", slot_faction_castle_guard_troop, "trp_nord_castle_guard"),
	    (faction_set_slot, ":faction_no",  slot_faction_reinforcements_a, "pt_kingdom_4_reinforcements_a"),
	    (faction_set_slot, ":faction_no",  slot_faction_reinforcements_b, "pt_kingdom_4_reinforcements_b"),
	    (faction_set_slot, ":faction_no",  slot_faction_reinforcements_c, "pt_kingdom_4_reinforcements_c"),
	  (else_try),
	    (faction_slot_eq, ":faction_no", slot_faction_culture, "fac_culture_5"),
	    
	    (faction_set_slot, ":faction_no", slot_faction_deserter_troop, "trp_rhodok_deserter"),
	    (faction_set_slot, ":faction_no", slot_faction_guard_troop, "trp_rhodok_veteran_spearman"),
	    (faction_set_slot, ":faction_no", slot_faction_messenger_troop, "trp_rhodok_messenger"),
	    (faction_set_slot, ":faction_no", slot_faction_prison_guard_troop, "trp_rhodok_prison_guard"),
	    (faction_set_slot, ":faction_no", slot_faction_castle_guard_troop, "trp_rhodok_castle_guard"),
	    (faction_set_slot, ":faction_no",  slot_faction_reinforcements_a, "pt_kingdom_5_reinforcements_a"),
	    (faction_set_slot, ":faction_no",  slot_faction_reinforcements_b, "pt_kingdom_5_reinforcements_b"),
	    (faction_set_slot, ":faction_no",  slot_faction_reinforcements_c, "pt_kingdom_5_reinforcements_c"),
	  (try_end),
	(try_end),




	# Towns:
	(try_for_range, ":item_no", trade_goods_begin, trade_goods_end),
	  (store_sub, ":offset", ":item_no", trade_goods_begin),
	  (val_add, ":offset", slot_town_trade_good_prices_begin),
	  (try_for_range, ":center_no", cities_begin, cities_end),
	    (party_set_slot, ":center_no", ":offset", average_price_factor),
	  (try_end),
	  (party_set_slot, "p_zendar", ":offset", average_price_factor),
	  (party_set_slot, "p_salt_mine", ":offset", average_price_factor),
	  (party_set_slot, "p_four_ways_inn", ":offset", average_price_factor),
	(try_end),

	(try_for_range, ":town_no", towns_begin, towns_end),
	  (call_script, "script_center_set_trade_good_production", ":town_no", "itm_smoked_fish", -15),
	  (call_script, "script_center_set_trade_good_production", ":town_no", "itm_dried_meat", -25),
	  (call_script, "script_center_set_trade_good_production", ":town_no", "itm_pork", -30),
	  (call_script, "script_center_set_trade_good_production", ":town_no", "itm_bread", -30),
	  (call_script, "script_center_set_trade_good_production", ":town_no", "itm_cheese", -20),
	  (call_script, "script_center_set_trade_good_production", ":town_no", "itm_chicken", -20),
	  (call_script, "script_center_set_trade_good_production", ":town_no", "itm_honey", -15),
	  (call_script, "script_center_set_trade_good_production", ":town_no", "itm_cabbages", -20),
	  (call_script, "script_center_set_trade_good_production", ":town_no", "itm_butter", -20),
	  (call_script, "script_center_set_trade_good_production", ":town_no", "itm_wine", -20),
	  (call_script, "script_center_set_trade_good_production", ":town_no", "itm_flour", -20),
	  (call_script, "script_center_set_trade_good_production", ":town_no", "itm_ale", -10),
	  (call_script, "script_center_set_trade_good_production", ":town_no", "itm_apples", -20),
	  (call_script, "script_center_set_trade_good_production", ":town_no", "itm_grain", -40),
	  
	  (call_script, "script_center_set_trade_good_production", "p_town_1", "itm_iron", -20),
	  (call_script, "script_center_set_trade_good_production", "p_town_2", "itm_wool", -30),
	  (call_script, "script_center_set_trade_good_production", "p_town_4", "itm_furs", -30),
	  (call_script, "script_center_set_trade_good_production", "p_town_4", "itm_oil", -30),
	  (call_script, "script_center_set_trade_good_production", "p_town_5", "itm_velvet", -10),
	  (call_script, "script_center_set_trade_good_production", "p_town_10", "itm_spice", -15),
	  (call_script, "script_center_set_trade_good_production", "p_town_14", "itm_linen", -10),
	(try_end),

	(party_set_slot,"p_town_1", slot_town_arena_melee_1_num_teams,   2),
	(party_set_slot,"p_town_1", slot_town_arena_melee_1_team_size,   1),
	(party_set_slot,"p_town_1", slot_town_arena_melee_2_num_teams,   4),
	(party_set_slot,"p_town_1", slot_town_arena_melee_2_team_size,   1),
	(party_set_slot,"p_town_1", slot_town_arena_melee_3_num_teams,   4),
	(party_set_slot,"p_town_1", slot_town_arena_melee_3_team_size,   1),
	(call_script, "script_center_set_trade_good_production", "p_town_1", "itm_linen", 40),
	(call_script, "script_center_set_trade_good_production", "p_town_1", "itm_iron", -30),

	(party_set_slot,"p_town_2", slot_town_arena_melee_1_num_teams,   4),
	(party_set_slot,"p_town_2", slot_town_arena_melee_1_team_size,   4),
	(party_set_slot,"p_town_2", slot_town_arena_melee_2_num_teams,   4),
	(party_set_slot,"p_town_2", slot_town_arena_melee_2_team_size,   6),
	(party_set_slot,"p_town_2", slot_town_arena_melee_3_num_teams,   4),
	(party_set_slot,"p_town_2", slot_town_arena_melee_3_team_size,   8),
	(call_script, "script_center_set_trade_good_production", "p_town_2", "itm_smoked_fish", 50),
	(call_script, "script_center_set_trade_good_production", "p_town_2", "itm_wool", -30),

	(party_set_slot,"p_town_3", slot_town_arena_melee_1_num_teams,   2),
	(party_set_slot,"p_town_3", slot_town_arena_melee_1_team_size,   8),
	(party_set_slot,"p_town_3", slot_town_arena_melee_2_num_teams,   2),
	(party_set_slot,"p_town_3", slot_town_arena_melee_2_team_size,   8),
	(party_set_slot,"p_town_3", slot_town_arena_melee_3_num_teams,   2),
	(party_set_slot,"p_town_3", slot_town_arena_melee_3_team_size,   8),
	(call_script, "script_center_set_trade_good_production", "p_town_3", "itm_wine", 30),
	(call_script, "script_center_set_trade_good_production", "p_town_3", "itm_dried_meat", -40),

	(party_set_slot,"p_town_4", slot_town_arena_melee_1_num_teams,   2),
	(party_set_slot,"p_town_4", slot_town_arena_melee_1_team_size,   8),
	(party_set_slot,"p_town_4", slot_town_arena_melee_2_num_teams,   3),
	(party_set_slot,"p_town_4", slot_town_arena_melee_2_team_size,   8),
	(party_set_slot,"p_town_4", slot_town_arena_melee_3_num_teams,   2),
	(party_set_slot,"p_town_4", slot_town_arena_melee_3_team_size,   5),
	(call_script, "script_center_set_trade_good_production", "p_town_4", "itm_oil", 40),
	(call_script, "script_center_set_trade_good_production", "p_town_4", "itm_furs", -40),

	(party_set_slot,"p_town_5", slot_town_arena_melee_1_num_teams,   2),
	(party_set_slot,"p_town_5", slot_town_arena_melee_1_team_size,   3),
	(party_set_slot,"p_town_5", slot_town_arena_melee_2_num_teams,   2),
	(party_set_slot,"p_town_5", slot_town_arena_melee_2_team_size,   5),
	(party_set_slot,"p_town_5", slot_town_arena_melee_3_num_teams,   2),
	(party_set_slot,"p_town_5", slot_town_arena_melee_3_team_size,   8),
	(call_script, "script_center_set_trade_good_production", "p_town_5", "itm_velvet", 40),
	(call_script, "script_center_set_trade_good_production", "p_town_5", "itm_pottery", -40),

	(party_set_slot,"p_town_6", slot_town_arena_melee_1_num_teams,   2),
	(party_set_slot,"p_town_6", slot_town_arena_melee_1_team_size,   4),
	(party_set_slot,"p_town_6", slot_town_arena_melee_2_num_teams,   3),
	(party_set_slot,"p_town_6", slot_town_arena_melee_2_team_size,   4),
	(party_set_slot,"p_town_6", slot_town_arena_melee_3_num_teams,   3),
	(party_set_slot,"p_town_6", slot_town_arena_melee_3_team_size,   6),
	(call_script, "script_center_set_trade_good_production", "p_town_6", "itm_ale", 40),
	(call_script, "script_center_set_trade_good_production", "p_town_6", "itm_spice", -40),

	(party_set_slot,"p_town_7", slot_town_arena_melee_1_num_teams,   4),
	(party_set_slot,"p_town_7", slot_town_arena_melee_1_team_size,   4),
	(party_set_slot,"p_town_7", slot_town_arena_melee_2_num_teams,   4),
	(party_set_slot,"p_town_7", slot_town_arena_melee_2_team_size,   6),
	(party_set_slot,"p_town_7", slot_town_arena_melee_3_num_teams,   4),
	(party_set_slot,"p_town_7", slot_town_arena_melee_3_team_size,   8),
	(call_script, "script_center_set_trade_good_production", "p_town_7", "itm_grain", 40),
	(call_script, "script_center_set_trade_good_production", "p_town_7", "itm_smoked_fish", -40),

	(party_set_slot,"p_town_8", slot_town_arena_melee_1_num_teams,   3),
	(party_set_slot,"p_town_8", slot_town_arena_melee_1_team_size,   1),
	(party_set_slot,"p_town_8", slot_town_arena_melee_2_num_teams,   3),
	(party_set_slot,"p_town_8", slot_town_arena_melee_2_team_size,   3),
	(party_set_slot,"p_town_8", slot_town_arena_melee_3_num_teams,   3),
	(party_set_slot,"p_town_8", slot_town_arena_melee_3_team_size,   7),
	(call_script, "script_center_set_trade_good_production", "p_town_8", "itm_wool", 40),
	(call_script, "script_center_set_trade_good_production", "p_town_8", "itm_velvet", -40),

	(party_set_slot,"p_town_9", slot_town_arena_melee_1_num_teams,   2),
	(party_set_slot,"p_town_9", slot_town_arena_melee_1_team_size,   2),
	(party_set_slot,"p_town_9", slot_town_arena_melee_2_num_teams,   2),
	(party_set_slot,"p_town_9", slot_town_arena_melee_2_team_size,   5),
	(party_set_slot,"p_town_9", slot_town_arena_melee_3_num_teams,   2),
	(party_set_slot,"p_town_9", slot_town_arena_melee_3_team_size,   8),
	(call_script, "script_center_set_trade_good_production", "p_town_9", "itm_furs", 40),
	(call_script, "script_center_set_trade_good_production", "p_town_9", "itm_ale", -40),

	(party_set_slot,"p_town_10", slot_town_arena_melee_1_num_teams,   2),
	(party_set_slot,"p_town_10", slot_town_arena_melee_1_team_size,   3),
	(party_set_slot,"p_town_10", slot_town_arena_melee_2_num_teams,   2),
	(party_set_slot,"p_town_10", slot_town_arena_melee_2_team_size,   5),
	(party_set_slot,"p_town_10", slot_town_arena_melee_3_num_teams,   2),
	(party_set_slot,"p_town_10", slot_town_arena_melee_3_team_size,   8),
	(call_script, "script_center_set_trade_good_production", "p_town_10", "itm_spice", 20),
	(call_script, "script_center_set_trade_good_production", "p_town_10", "itm_grain", -40),
	(call_script, "script_center_set_trade_good_production", "p_town_10", "itm_tools", -40),

	(party_set_slot,"p_town_11", slot_town_arena_melee_1_num_teams,   2),
	(party_set_slot,"p_town_11", slot_town_arena_melee_1_team_size,   8),
	(party_set_slot,"p_town_11", slot_town_arena_melee_2_num_teams,   3),
	(party_set_slot,"p_town_11", slot_town_arena_melee_2_team_size,   4),
	(party_set_slot,"p_town_11", slot_town_arena_melee_3_num_teams,   3),
	(party_set_slot,"p_town_11", slot_town_arena_melee_3_team_size,   6),
	(call_script, "script_center_set_trade_good_production", "p_town_11", "itm_iron", 50),
	(call_script, "script_center_set_trade_good_production", "p_town_11", "itm_dried_meat", -50),

	(party_set_slot,"p_town_12", slot_town_arena_melee_1_num_teams,   3),
	(party_set_slot,"p_town_12", slot_town_arena_melee_1_team_size,   8),
	(party_set_slot,"p_town_12", slot_town_arena_melee_2_num_teams,   4),
	(party_set_slot,"p_town_12", slot_town_arena_melee_2_team_size,   6),
	(party_set_slot,"p_town_12", slot_town_arena_melee_3_num_teams,   4),
	(party_set_slot,"p_town_12", slot_town_arena_melee_3_team_size,   5),
	(call_script, "script_center_set_trade_good_production", "p_town_12", "itm_smoked_fish", 50),
	(call_script, "script_center_set_trade_good_production", "p_town_12", "itm_wine", -60),

	(party_set_slot,"p_town_13", slot_town_arena_melee_1_num_teams,   2),
	(party_set_slot,"p_town_13", slot_town_arena_melee_1_team_size,   8),
	(party_set_slot,"p_town_13", slot_town_arena_melee_2_num_teams,   4),
	(party_set_slot,"p_town_13", slot_town_arena_melee_2_team_size,   5),
	(party_set_slot,"p_town_13", slot_town_arena_melee_3_num_teams,   4),
	(party_set_slot,"p_town_13", slot_town_arena_melee_3_team_size,   7),
	(call_script, "script_center_set_trade_good_production", "p_town_13", "itm_dried_meat", 50),
	(call_script, "script_center_set_trade_good_production", "p_town_13", "itm_oil", -40),

	(party_set_slot,"p_town_14", slot_town_arena_melee_1_num_teams,   2),
	(party_set_slot,"p_town_14", slot_town_arena_melee_1_team_size,   4),
	(party_set_slot,"p_town_14", slot_town_arena_melee_2_num_teams,   2),
	(party_set_slot,"p_town_14", slot_town_arena_melee_2_team_size,   5),
	(party_set_slot,"p_town_14", slot_town_arena_melee_3_num_teams,   2),
	(party_set_slot,"p_town_14", slot_town_arena_melee_3_team_size,   6),
	(call_script, "script_center_set_trade_good_production", "p_town_14", "itm_pottery", 50),
	(call_script, "script_center_set_trade_good_production", "p_town_14", "itm_linen", -40),

	# Towns (loop)
	(try_for_range, ":town_no", towns_begin, towns_end),
	  (store_sub, ":offset", ":town_no", towns_begin),
	  (party_set_slot,":town_no", slot_party_type, spt_town),
	  #        (store_add, ":cur_object_no", "trp_town_1_seneschal", ":offset"),
	  #        (party_set_slot,":town_no", slot_town_seneschal, ":cur_object_no"),
	  (store_add, ":cur_object_no", "scn_town_1_center", ":offset"),
	  (party_set_slot,":town_no", slot_town_center, ":cur_object_no"),
	  (store_add, ":cur_object_no", "scn_town_1_castle", ":offset"),
	  (party_set_slot,":town_no", slot_town_castle, ":cur_object_no"),
	  (store_add, ":cur_object_no", "scn_town_1_prison", ":offset"),
	  (party_set_slot,":town_no", slot_town_prison, ":cur_object_no"),
	  (store_add, ":cur_object_no", "scn_town_1_tavern", ":offset"),
	  (party_set_slot,":town_no", slot_town_tavern, ":cur_object_no"),
	  (store_add, ":cur_object_no", "scn_town_1_store", ":offset"),
	  (party_set_slot,":town_no", slot_town_store, ":cur_object_no"),
	  (store_add, ":cur_object_no", "scn_town_1_arena", ":offset"),
	  (party_set_slot,":town_no", slot_town_arena, ":cur_object_no"),
	  (store_add, ":cur_object_no", "scn_town_1_alley", ":offset"),
	  (party_set_slot,":town_no", slot_town_alley, ":cur_object_no"),
	  (store_add, ":cur_object_no", "trp_town_1_tavernkeeper", ":offset"),
	  (party_set_slot,":town_no", slot_town_tavernkeeper, ":cur_object_no"),
	  (store_add, ":cur_object_no", "trp_town_1_weaponsmith", ":offset"),
	  (party_set_slot,":town_no", slot_town_weaponsmith, ":cur_object_no"),
	  (store_add, ":cur_object_no", "trp_town_1_armorer", ":offset"),
	  (party_set_slot,":town_no", slot_town_armorer, ":cur_object_no"),
	  (store_add, ":cur_object_no", "trp_town_1_merchant", ":offset"),
	  (party_set_slot,":town_no", slot_town_merchant, ":cur_object_no"),
	  (store_add, ":cur_object_no", "trp_town_1_horse_merchant", ":offset"),
	  (party_set_slot,":town_no", slot_town_horse_merchant, ":cur_object_no"),
	  (store_add, ":cur_object_no", "p_town_1_mercs", ":offset"),
	  (party_set_slot,":town_no", slot_town_mercs, ":cur_object_no"),
	  (store_add, ":cur_object_no", "scn_town_1_center", ":offset"),
	  (party_set_slot,":town_no", slot_town_center, ":cur_object_no"),
	  (party_set_slot,":town_no", slot_town_arena_template, "mt_arena_melee_fight"),
	  (party_set_slot,":town_no", slot_town_reinforcement_party_template, "pt_center_reinforcements"),
	(try_end),

	(party_set_slot,"p_town_1", slot_town_arena_template, "mt_arena_melee_fight_no_ranged"),

	# Castles
	(try_for_range, ":castle_no", castles_begin, castles_end),
	  (store_sub, ":offset", ":castle_no", castles_begin),
	  (val_mul, ":offset", 2),
	  
	  #        (store_add, ":senechal_troop_no", "trp_castle_1_seneschal", ":offset"),
	  #        (party_set_slot,":castle_no", slot_town_seneschal, ":senechal_troop_no"),
	  (store_add, ":exterior_scene_no", "scn_castle_1_exterior", ":offset"),
	  (party_set_slot,":castle_no", slot_castle_exterior, ":exterior_scene_no"),
	  (store_add, ":interior_scene_no", "scn_castle_1_interior", ":offset"),
	  (party_set_slot,":castle_no", slot_town_castle, ":interior_scene_no"),
	  (party_set_slot,":castle_no", slot_town_reinforcement_party_template, "pt_center_reinforcements"),
	  (party_set_slot,":castle_no", slot_party_type, spt_castle),
	  (party_set_slot,":castle_no", slot_town_is_besieged_by, -1),
	(try_end),

	# Set which castles need to be attacked with siege towers.
	(party_set_slot,"p_castle_1", slot_center_siege_with_belfry,   0),
	(party_set_slot,"p_castle_2", slot_center_siege_with_belfry,   1),
	(party_set_slot,"p_castle_3", slot_center_siege_with_belfry,   0),
	(party_set_slot,"p_castle_4", slot_center_siege_with_belfry,   0),
	(party_set_slot,"p_castle_5", slot_center_siege_with_belfry,   0),
	(party_set_slot,"p_castle_6", slot_center_siege_with_belfry,   0),
	(party_set_slot,"p_castle_7", slot_center_siege_with_belfry,   1),
	(party_set_slot,"p_castle_8", slot_center_siege_with_belfry,   1),
	(party_set_slot,"p_castle_9", slot_center_siege_with_belfry,   1),
	(party_set_slot,"p_castle_10", slot_center_siege_with_belfry,   0),
	(party_set_slot,"p_castle_11", slot_center_siege_with_belfry,   1),


	# Towns

	# Villages
	#TODO: add smoked fish to coastal villages.
	(call_script, "script_center_set_trade_good_production", "p_village_1", "itm_smoked_fish", 60),
	(try_for_range, ":village_no", villages_begin, villages_end),
	  (store_random_in_range, ":rand", 0, 9),
	  (val_mul, ":rand", ":rand"),
	  (call_script, "script_center_set_trade_good_production", ":village_no", "itm_dried_meat", ":rand"),
	  (store_random_in_range, ":rand", 0, 9),
	  (val_mul, ":rand", ":rand"),
	  (call_script, "script_center_set_trade_good_production", ":village_no", "itm_pork", ":rand"),
	  (store_random_in_range, ":rand", 0, 9),
	  (val_mul, ":rand", ":rand"),
	  (call_script, "script_center_set_trade_good_production", ":village_no", "itm_bread", ":rand"),
	  (store_random_in_range, ":rand", 0, 9),
	  (val_mul, ":rand", ":rand"),
	  (call_script, "script_center_set_trade_good_production", ":village_no", "itm_apples", ":rand"),
	  (store_random_in_range, ":rand", 0, 9),
	  (val_mul, ":rand", ":rand"),
	  (call_script, "script_center_set_trade_good_production", ":village_no", "itm_cheese", ":rand"),
	  (store_random_in_range, ":rand", 0, 9),
	  (val_mul, ":rand", ":rand"),
	  (call_script, "script_center_set_trade_good_production", ":village_no", "itm_chicken", ":rand"),
	  (store_random_in_range, ":rand", 0, 9),
	  (val_mul, ":rand", ":rand"),
	  (call_script, "script_center_set_trade_good_production", ":village_no", "itm_honey", ":rand"),
	  (store_random_in_range, ":rand", 0, 9),
	  (val_mul, ":rand", ":rand"),
	  (call_script, "script_center_set_trade_good_production", ":village_no", "itm_cabbages", ":rand"),
	  (store_random_in_range, ":rand", 0, 9),
	  (val_mul, ":rand", ":rand"),
	  (call_script, "script_center_set_trade_good_production", ":village_no", "itm_butter", ":rand"),
	  (store_random_in_range, ":rand", 0, 9),
	  (val_mul, ":rand", ":rand"),
	  (call_script, "script_center_set_trade_good_production", ":village_no", "itm_wine", ":rand"),
	  (store_random_in_range, ":rand", 0, 9),
	  (val_mul, ":rand", ":rand"),
	  (call_script, "script_center_set_trade_good_production", ":village_no", "itm_flour", ":rand"),
	  (store_random_in_range, ":rand", 0, 9),
	  (val_mul, ":rand", ":rand"),
	  (call_script, "script_center_set_trade_good_production", ":village_no", "itm_ale", ":rand"),
	  (store_random_in_range, ":rand", 0, 9),
	  (val_mul, ":rand", ":rand"),
	  (call_script, "script_center_set_trade_good_production", ":village_no", "itm_apples", ":rand"),
	  (store_random_in_range, ":rand", 0, 9),
	  (val_mul, ":rand", ":rand"),
	  (call_script, "script_center_set_trade_good_production", ":village_no", "itm_grain", ":rand"),
	  (store_random_in_range, ":rand", 0, 9),
	  (val_mul, ":rand", ":rand"),
	  (call_script, "script_center_set_trade_good_production", ":village_no", "itm_oil", ":rand"),
	(try_end),

	(try_for_range, ":village_no", villages_begin, villages_end),
	  (store_sub, ":offset", ":village_no", villages_begin),
	  
	  (store_add, ":exterior_scene_no", "scn_village_1", ":offset"),
	  (party_set_slot,":village_no", slot_castle_exterior, ":exterior_scene_no"),
	  
	  (store_add, ":store_troop_no", "trp_village_1_store", ":offset"),
	  (party_set_slot,":village_no", slot_town_merchant, ":store_troop_no"),
	  
	  (party_set_slot,":village_no", slot_party_type, spt_village),
	  (party_set_slot,":village_no", slot_town_raided_by, -1),
	  
	  (call_script, "script_refresh_village_merchant_inventory", ":village_no"),
	  (call_script, "script_refresh_village_merchant_inventory", ":village_no"),
	  
	  (call_script, "script_refresh_village_defenders", ":village_no"),
	  (call_script, "script_refresh_village_defenders", ":village_no"),
	  (call_script, "script_refresh_village_defenders", ":village_no"),
	  (call_script, "script_refresh_village_defenders", ":village_no"),
	(try_end),

	#TODO: These villages have no scenes yet and are linked to existing village scenes
	(party_set_slot,"p_village_10", slot_castle_exterior, "scn_village_7"),

	(party_set_slot,"p_village_24", slot_castle_exterior, "scn_village_4"),
	(party_set_slot,"p_village_26", slot_castle_exterior, "scn_village_6"),
	(party_set_slot,"p_village_27", slot_castle_exterior, "scn_village_3"),
	(party_set_slot,"p_village_29", slot_castle_exterior, "scn_village_9"),
	(party_set_slot,"p_village_30", slot_castle_exterior, "scn_village_5"),
	(party_set_slot,"p_village_31", slot_castle_exterior, "scn_village_1"),
	(party_set_slot,"p_village_32", slot_castle_exterior, "scn_village_2"),
	(party_set_slot,"p_village_33", slot_castle_exterior, "scn_village_3"),
	(party_set_slot,"p_village_34", slot_castle_exterior, "scn_village_4"),
	(party_set_slot,"p_village_35", slot_castle_exterior, "scn_village_5"),
	(party_set_slot,"p_village_36", slot_castle_exterior, "scn_village_6"),
	(party_set_slot,"p_village_38", slot_castle_exterior, "scn_village_8"),
	(party_set_slot,"p_village_39", slot_castle_exterior, "scn_village_9"),


	(try_for_range, ":center_no", cities_begin, cities_end),
	  (party_set_slot, ":center_no", slot_center_last_spotted_enemy, -1),
	  (party_set_slot, ":center_no", slot_town_is_besieged_by, -1),
	  (party_set_slot, ":center_no", slot_center_last_taken_by_troop, -1),
	(try_end),

	# Troops:

	# Assign banners and renown.
	# We assume there are enough banners for all kingdom heroes.
	(try_for_range, ":kingdom_hero", kingdom_heroes_begin, kingdom_heroes_end),
	  (store_sub, ":hero_offset", ":kingdom_hero", kingdom_heroes_begin),
	  #        (lt, ":hero_offset", num_banners),
	  (store_add, ":banner_id", "spr_banner_a", ":hero_offset"),
	  (troop_set_slot,":kingdom_hero",  slot_troop_banner_scene_prop, ":banner_id"),
	  (store_troop_faction, ":kingdom_hero_faction", ":kingdom_hero"),
	  (try_begin),
	    (faction_slot_eq, ":kingdom_hero_faction", slot_faction_leader, ":kingdom_hero"),
	    (store_random_in_range, ":random_renown", 200, 400),
	  (else_try),
	    (store_random_in_range, ":random_renown", 50, 200),
	  (try_end),
	  (troop_set_slot, ":kingdom_hero", slot_troop_renown, ":random_renown"),
	(try_end),

	#Correcting banners according to the player banner
	(troop_get_slot, ":selected_banner_spr", "trp_player", slot_troop_banner_scene_prop),
	(assign, ":end_cond", kingdom_heroes_end),
	(try_for_range, ":cur_troop", kingdom_heroes_begin, ":end_cond"),
	  (troop_slot_eq, ":cur_troop", slot_troop_banner_scene_prop, ":selected_banner_spr"),
	  (troop_set_slot, ":cur_troop", slot_troop_banner_scene_prop, "spr_banner_cu"),
	  (assign, ":end_cond", 0),
	(try_end),


	(call_script, "script_give_center_to_lord", "p_town_1",  "trp_kingdom_4_lord"),
	(call_script, "script_give_center_to_lord", "p_town_2",  "trp_knight_4_1"),
	(call_script, "script_give_center_to_lord", "p_town_3",  "trp_knight_5_1"),
	(call_script, "script_give_center_to_lord", "p_town_4",  "trp_knight_1_1"),
	(call_script, "script_give_center_to_lord", "p_town_5",  "trp_kingdom_5_lord"),
	(call_script, "script_give_center_to_lord", "p_town_6",  "trp_kingdom_1_lord"),
	(call_script, "script_give_center_to_lord", "p_town_7",  "trp_knight_1_2"),

	(call_script, "script_give_center_to_lord", "p_town_8",  "trp_kingdom_2_lord"),
	(call_script, "script_give_center_to_lord", "p_town_9",  "trp_knight_2_1"),
	(call_script, "script_give_center_to_lord", "p_town_10", "trp_kingdom_3_lord"),
	(call_script, "script_give_center_to_lord", "p_town_11", "trp_knight_3_1"),
	(call_script, "script_give_center_to_lord", "p_town_12", "trp_knight_4_2"),
	(call_script, "script_give_center_to_lord", "p_town_13", "trp_knight_2_2"),
	(call_script, "script_give_center_to_lord", "p_town_14", "trp_knight_3_2"),



	(call_script, "script_give_center_to_faction_aux", "p_castle_1", "fac_kingdom_5"),
	(call_script, "script_give_center_to_faction_aux", "p_castle_2", "fac_kingdom_3"),
	(call_script, "script_give_center_to_faction_aux", "p_castle_3", "fac_kingdom_2"),
	(call_script, "script_give_center_to_faction_aux", "p_castle_4", "fac_kingdom_1"),
	(call_script, "script_give_center_to_faction_aux", "p_castle_5", "fac_kingdom_4"),
	(call_script, "script_give_center_to_faction_aux", "p_castle_6", "fac_kingdom_2"),
	(call_script, "script_give_center_to_faction_aux", "p_castle_7", "fac_kingdom_3"),
	(call_script, "script_give_center_to_faction_aux", "p_castle_8", "fac_kingdom_2"),
	(call_script, "script_give_center_to_faction_aux", "p_castle_9", "fac_kingdom_5"),
	(call_script, "script_give_center_to_faction_aux", "p_castle_10", "fac_kingdom_1"),
	(call_script, "script_give_center_to_faction_aux", "p_castle_11", "fac_kingdom_4"),

	##      (call_script, "script_give_center_to_lord", "p_castle_1",  "trp_knight_5_2"),
	##      (call_script, "script_give_center_to_lord", "p_castle_2",  "trp_knight_3_3"),
	##      (call_script, "script_give_center_to_lord", "p_castle_3",  "trp_knight_2_3"),
	##      (call_script, "script_give_center_to_lord", "p_castle_4",  "trp_knight_1_3"),
	##      (call_script, "script_give_center_to_lord", "p_castle_5",  "trp_knight_4_3"),
	##      (call_script, "script_give_center_to_lord", "p_castle_6",  "trp_knight_2_4"),
	##      (call_script, "script_give_center_to_lord", "p_castle_7",  "trp_knight_3_4"),
	##      (call_script, "script_give_center_to_lord", "p_castle_8",  "trp_knight_2_4"),
	##      (call_script, "script_give_center_to_lord", "p_castle_9",  "trp_knight_5_3"),
	##      (call_script, "script_give_center_to_lord", "p_castle_10", "trp_knight_1_4"),
	##      (call_script, "script_give_center_to_lord", "p_castle_11", "trp_knight_4_4"),


	# fill_village_bound_centers
	#pass 1: Give one village to each castle and town
	(try_for_range, ":cur_center", walled_cities_begin, walled_cities_end),
	  (assign, ":min_dist", 999999),
	  (assign, ":min_dist_village", -1),
	  (try_for_range, ":cur_village", villages_begin, villages_end),
	    (store_distance_to_party_from_party, ":cur_dist", ":cur_village", ":cur_center"),
	    (lt, ":cur_dist", ":min_dist"),
	    (assign, ":min_dist", ":cur_dist"),
	    (assign, ":min_dist_village", ":cur_village"),
	  (try_end),
	  (party_set_slot, ":min_dist_village", slot_village_bound_center, ":cur_center"),
	  (store_faction_of_party, ":town_faction", ":cur_center"),
	  (call_script, "script_give_center_to_faction_aux", ":min_dist_village", ":town_faction"),
	(try_end),

	#pass 2: Give other villages to closest town.
	(try_for_range, ":cur_village", villages_begin, villages_end),
	  (neg|party_slot_ge, ":cur_village", slot_village_bound_center, 1), #skip villages which are already bound.
	  (assign, ":min_dist", 999999),
	  (assign, ":min_dist_town", -1),
	  (try_for_range, ":cur_town", towns_begin, towns_end),
	    (store_distance_to_party_from_party, ":cur_dist", ":cur_village", ":cur_town"),
	    (lt, ":cur_dist", ":min_dist"),
	    (assign, ":min_dist", ":cur_dist"),
	    (assign, ":min_dist_town", ":cur_town"),
	  (try_end),
	  (party_set_slot, ":cur_village", slot_village_bound_center, ":min_dist_town"),
	  (store_faction_of_party, ":town_faction", ":min_dist_town"),
	  (call_script, "script_give_center_to_faction_aux", ":cur_village", ":town_faction"),
	(try_end),

	(try_for_range, ":center_no", cities_begin, cities_end),
	  (store_faction_of_party, ":original_faction", ":center_no"),
	  (faction_get_slot, ":culture", ":original_faction", slot_faction_culture),
	  (party_set_slot, ":center_no", slot_center_culture,  ":culture"),
	(try_end),

	(call_script, "script_update_village_market_towns"),

	#Assign only family structures of lords who doesn't have a father. Other troops will get the family tree automatically
	(troop_set_slot,"trp_kingdom_1_lord",  slot_troop_spouse, "trp_kingdom_1_lord_wife"),
	(troop_set_slot,"trp_kingdom_2_lord",  slot_troop_spouse, "trp_kingdom_2_lord_wife"),
	(troop_set_slot,"trp_kingdom_3_lord",  slot_troop_spouse, "trp_kingdom_3_lord_wife"),
	(troop_set_slot,"trp_kingdom_4_lord",  slot_troop_spouse, "trp_kingdom_4_lord_wife"),
	(troop_set_slot,"trp_kingdom_5_lord",  slot_troop_spouse, "trp_kingdom_5_lord_wife"),

	(troop_set_slot,"trp_kingdom_1_lord",  slot_troop_daughter, "trp_kingdom_1_lord_daughter"),
	(troop_set_slot,"trp_kingdom_2_lord",  slot_troop_daughter, "trp_kingdom_2_lord_daughter"),
	(troop_set_slot,"trp_kingdom_3_lord",  slot_troop_daughter, "trp_kingdom_3_lord_daughter"),
	(troop_set_slot,"trp_kingdom_4_lord",  slot_troop_daughter, "trp_kingdom_4_lord_daughter"),
	(troop_set_slot,"trp_kingdom_5_lord",  slot_troop_daughter, "trp_kingdom_5_lord_daughter"),

	##      (troop_set_slot,"trp_kingdom_2_lord_a", slot_troop_spouse, "trp_kingdom_2_lady_a"),
	##      (troop_set_slot,"trp_kingdom_2_lord_a", slot_troop_son, "trp_kingdom_2_lord_b"),
	##      (troop_set_slot,"trp_kingdom_2_lord_a", slot_troop_sibling, "trp_kingdom_2_lady_c"),
	##      (troop_set_slot,"trp_kingdom_2_lord_a", slot_troop_daughter, "trp_kingdom_2_lady_e"),
	##
	##      (troop_set_slot,"trp_kingdom_2_lord_b", slot_troop_daughter, "trp_kingdom_2_lady_b"),
	##      (troop_set_slot,"trp_kingdom_2_lord_c", slot_troop_spouse, "trp_kingdom_2_lady_c"),
	##      (troop_set_slot,"trp_kingdom_2_lord_d", slot_troop_daughter, "trp_kingdom_2_lady_d"),
	##      (troop_set_slot,"trp_kingdom_2_lord_e", slot_troop_spouse, "trp_kingdom_2_lady_e"),
	##      (troop_set_slot,"trp_kingdom_2_lord_f", slot_troop_daughter, "trp_kingdom_2_lady_f"),
	##      (troop_set_slot,"trp_kingdom_2_lord_g", slot_troop_spouse, "trp_kingdom_2_lady_g"),
	##      (troop_set_slot,"trp_kingdom_2_lord_h", slot_troop_daughter, "trp_kingdom_2_lady_h"),
	##      (troop_set_slot,"trp_kingdom_2_lord_i", slot_troop_spouse, "trp_kingdom_2_lady_i"),
	##      (troop_set_slot,"trp_kingdom_2_lord_j", slot_troop_daughter, "trp_kingdom_2_lady_j"),

	##      (try_for_range, ":troop_id", merchants_begin, merchants_end),
	##        (troop_set_slot, ":troop_id", slot_troop_occupation, slto_merchant),
	##      (try_end),

	(try_for_range, ":troop_id", kingdom_heroes_begin, kingdom_heroes_end),
	  (try_begin),
	    (store_troop_faction, ":faction_id", ":troop_id"),
	    (is_between, ":faction_id", factions_begin, factions_end),
	    (troop_set_slot, ":troop_id", slot_troop_occupation, slto_kingdom_hero),
	  (try_end),
	  (assign, ":initial_wealth", 6000),
	  (try_begin),
	    (store_troop_faction, ":faction", ":troop_id"),
	    (faction_slot_eq, ":faction", slot_faction_leader, ":troop_id"),
	    (assign, ":initial_wealth", 20000),
	  (try_end),
	  (troop_set_slot, ":troop_id", slot_troop_wealth, ":initial_wealth"),
	(try_end),

	(try_for_range, ":center_no", walled_cities_begin, walled_cities_end),
	  (assign, ":garrison_strength", 8), #add town garrisons
	  (try_for_range, ":unused", 0, ":garrison_strength"),
	    (call_script, "script_cf_reinforce_party", ":center_no"),
	  (try_end),
	  
	  #Fill town food stores upto half the limit
	  (call_script, "script_center_get_food_store_limit", ":center_no"),
	  (assign, ":food_store_limit", reg0),
	  (val_div, ":food_store_limit", 2),
	  (party_set_slot, ":center_no", slot_town_food_stores, ":food_store_limit"),
	  
	  #create lord parties
	  (party_get_slot, ":center_lord", ":center_no", slot_town_lord),
	  (ge, ":center_lord", 1),
	  (troop_slot_eq, ":center_lord", slot_troop_leaded_party, 0),
	  (call_script, "script_create_kingdom_hero_party", ":center_lord", ":center_no"),
	  (assign, ":lords_party", "$pout_party"),
	  (party_attach_to_party, ":lords_party", ":center_no"),
	  (store_random_in_range, ":xp", 4000, 10000),
	  (call_script, "script_upgrade_hero_party", ":lords_party", ":xp"),
	  (party_set_slot, ":center_no", slot_town_player_odds, 1000),
	(try_end),

	(call_script, "script_complete_family_relations"),
	(call_script, "script_complete_family_relations"),

	(try_for_range, ":troop_id", kingdom_ladies_begin, kingdom_ladies_end),
	  (troop_set_slot, ":troop_id", slot_troop_occupation, slto_kingdom_lady),
	  (troop_get_slot, ":cur_family", ":troop_id", slot_troop_father),
	  (try_begin),
	    (eq, ":cur_family", 0),
	    (troop_get_slot, ":cur_family", ":troop_id", slot_troop_spouse),
	  (try_end),
	  (try_begin),
	    (gt, ":cur_family", 0),
	    (call_script, "script_get_troop_attached_party", ":cur_family"),
	    (assign, ":cur_center", reg0),
	    (gt, ":cur_center", 0),
	    (troop_set_slot, ":troop_id", slot_troop_cur_center, ":cur_center"),
	  (else_try),
	    (store_troop_faction, ":faction_no", ":troop_id"),
	    (call_script, "script_cf_select_random_center_with_faction", ":faction_no"),
	    (assign, ":cur_center", reg0),
	    (troop_set_slot, ":troop_id", slot_troop_cur_center, ":cur_center"),
	  (try_end),
	(try_end),

	(try_for_range, ":troop_id", heroes_begin, heroes_end),
	  (troop_slot_eq, ":troop_id", slot_troop_occupation, slto_kingdom_lady),
	  (troop_get_slot, ":cur_father", ":troop_id", slot_troop_father),
	  (gt, ":cur_father", 0),# Lovers for daughters only
	  (store_random_in_range, ":random_no", 0, 100),
	  (le, ":random_no", 80),
	  (call_script, "script_cf_get_random_kingdom_hero_as_lover", ":troop_id"),#Can fail
	  (assign, ":cur_lover", reg0),
	  (troop_set_slot, ":troop_id", slot_troop_lover, ":cur_lover"),
	  (troop_set_slot, ":cur_lover", slot_troop_lover, ":troop_id"),
	(try_end),

	(try_for_range, ":troop_id", heroes_begin, heroes_end),
	  (troop_get_slot, ":in_relation_1", ":troop_id", slot_troop_spouse),
	  (troop_get_slot, ":in_relation_2", ":troop_id", slot_troop_sibling),
	  (troop_get_slot, ":in_relation_3", ":troop_id", slot_troop_daughter),
	  (troop_get_slot, ":in_relation_4", ":troop_id", slot_troop_son),
	  (troop_get_slot, ":in_relation_5", ":troop_id", slot_troop_father),
	  (troop_get_slot, ":in_relation_6", ":troop_id", slot_troop_mother),
	  (troop_get_slot, ":in_relation_7", ":troop_id", slot_troop_lover),
	  #        (troop_get_slot, ":troop_rank", ":troop_id", slot_troop_kingdom_rank),
	  (store_troop_faction, ":troop_faction", ":troop_id"),
	  
	  (assign, ":troop_enemy_count", 0),
	  (try_for_range, ":i_enemy_slot", slot_troop_enemies_begin, slot_troop_enemies_end),
	    (troop_slot_ge, ":troop_id", ":i_enemy_slot", 1),
	    (val_add, ":troop_enemy_count", 1),
	  (try_end),
	  
	  (try_for_range, ":i_enemy_slot", slot_troop_enemies_begin, slot_troop_enemies_end),
	    (troop_set_slot, ":troop_id", ":i_enemy_slot", -1),
	  (try_end),
	  
	  (store_random_in_range, ":random_enemy_count", 0, 4),
	  (val_add, ":random_enemy_count", ":troop_enemy_count"),
	  (val_min, ":random_enemy_count", 5),
	  (try_for_range, ":unused", ":troop_enemy_count", ":random_enemy_count"),
	    (assign, ":possible_enemy_count", 0),
	    (try_for_range, ":enemy_troop_id", heroes_begin, heroes_end),
	      (neq, ":enemy_troop_id", ":troop_id"),
	      (neq, ":enemy_troop_id", ":in_relation_1"),
	      (neq, ":enemy_troop_id", ":in_relation_2"),
	      (neq, ":enemy_troop_id", ":in_relation_3"),
	      (neq, ":enemy_troop_id", ":in_relation_4"),
	      (neq, ":enemy_troop_id", ":in_relation_5"),
	      (neq, ":enemy_troop_id", ":in_relation_6"),
	      (neq, ":enemy_troop_id", ":in_relation_7"),
	      (store_troop_faction, ":enemy_troop_faction", ":enemy_troop_id"),
	      (eq, ":enemy_troop_faction", ":troop_faction"),
	      #            (troop_get_slot, ":enemy_troop_rank", ":enemy_troop_id", slot_troop_kingdom_rank),
	      #            (lt, ":enemy_troop_rank", 4),
	      #            (lt, ":troop_rank", 4),
	      (assign, ":marked_as_enemy", 0),
	      (try_for_range, ":i_enemy_slot_mark", slot_troop_enemies_begin, slot_troop_enemies_end),
	        (troop_slot_eq, ":troop_id", ":i_enemy_slot_mark", ":enemy_troop_id"),
	        (assign, ":marked_as_enemy", 1),
	      (try_end),
	      (eq, ":marked_as_enemy", 0),
	      (val_add, ":possible_enemy_count", 1),
	    (try_end),
	    (store_random_in_range, ":random_enemy", 0, ":possible_enemy_count"),
	    (assign, ":possible_enemy_count", 0),
	    (assign, ":result", -1),
	    (try_for_range, ":enemy_troop_id", heroes_begin, heroes_end),
	      (eq, ":result", -1),
	      (neq, ":enemy_troop_id", ":troop_id"),
	      (neq, ":enemy_troop_id", ":in_relation_1"),
	      (neq, ":enemy_troop_id", ":in_relation_2"),
	      (neq, ":enemy_troop_id", ":in_relation_3"),
	      (neq, ":enemy_troop_id", ":in_relation_4"),
	      (neq, ":enemy_troop_id", ":in_relation_5"),
	      (neq, ":enemy_troop_id", ":in_relation_6"),
	      (neq, ":enemy_troop_id", ":in_relation_7"),
	      (store_troop_faction, ":enemy_troop_faction", ":enemy_troop_id"),
	      (eq, ":enemy_troop_faction", ":troop_faction"),
	      #            (troop_get_slot, ":enemy_troop_rank", ":enemy_troop_id", slot_troop_kingdom_rank),
	      #            (lt, ":enemy_troop_rank", 4),
	      #            (lt, ":troop_rank", 4),
	      (assign, ":marked_as_enemy", 0),
	      (try_for_range, ":i_enemy_slot_mark", slot_troop_enemies_begin, slot_troop_enemies_end),
	        (troop_slot_eq, ":troop_id", ":i_enemy_slot_mark", ":enemy_troop_id"),
	        (assign, ":marked_as_enemy", 1),
	      (try_end),
	      (eq, ":marked_as_enemy", 0),
	      (val_add, ":possible_enemy_count", 1),
	      (gt, ":possible_enemy_count", ":random_enemy"),
	      (assign, ":result", ":enemy_troop_id"),
	    (try_end),
	    
	    (gt, ":result", 0),
	    (assign, ":enemy_troop_enemy_count", 0),
	    (try_for_range, ":i_enemy_slot", slot_troop_enemies_begin, slot_troop_enemies_end),
	      (troop_slot_ge, ":result", ":i_enemy_slot", 1),
	      (val_add, ":enemy_troop_enemy_count", 1),
	    (try_end),
	    
	    (lt, ":enemy_troop_enemy_count", 5),
	    
	    (assign, ":troop_enemy_count", 0),
	    (try_for_range, ":i_enemy_slot", slot_troop_enemies_begin, slot_troop_enemies_end),
	      (troop_slot_ge, ":troop_id", ":i_enemy_slot", 1),
	      (val_add, ":troop_enemy_count", 1),
	    (try_end),
	    
	    (store_add, ":cur_slot", slot_troop_enemies_begin, ":troop_enemy_count"),
	    (troop_set_slot, ":troop_id", ":cur_slot", ":result"),
	    (store_add, ":cur_slot", slot_troop_enemies_begin, ":enemy_troop_enemy_count"),
	    (troop_set_slot, ":result", ":cur_slot", ":troop_id"),
	  (try_end),
	(try_end),

	#      (call_script, "script_average_trade_good_productions"),

	(try_for_range, ":unused", 0, 7),
	  (call_script, "script_spawn_bandits"),
	(try_end),
	(call_script, "script_update_trade_good_prices"),
	(call_script, "script_update_trade_good_prices"),
	(call_script, "script_update_trade_good_prices"),
	(call_script, "script_update_trade_good_prices"),
	(call_script, "script_update_trade_good_prices"),

	(call_script, "script_assign_lords_to_empty_centers"),

	(call_script, "script_process_player_party_morale"),

	(call_script, "script_update_mercenary_units_of_towns"),
	(call_script, "script_update_companion_candidates_in_taverns"),
	(call_script, "script_update_ransom_brokers"),
	(call_script, "script_update_tavern_travelers"),
	(call_script, "script_update_tavern_minstels"),
	(try_for_range, ":village_no", villages_begin, villages_end),
	  (call_script, "script_update_volunteer_troops_in_village", ":village_no"),
	(try_end),
	(try_for_range, ":cur_kingdom", factions_begin, factions_end),
	  (call_script, "script_update_faction_notes", ":cur_kingdom"),
	(try_end),
	(try_for_range, ":cur_troop", kingdom_heroes_begin, kingdom_heroes_end),
	  (call_script, "script_update_troop_notes", ":cur_troop"),
	(try_end),
	(call_script, "script_update_troop_notes", "trp_player"),


	("kingdom_hero_decide_next_ai_state",
	  [
	    (store_script_param_1, ":troop_no"),
	    (try_begin),
	      (troop_get_slot, ":party_no", ":troop_no", slot_troop_leaded_party),
	      (gt, ":party_no", 0),
	      (troop_slot_eq, ":troop_no", slot_troop_occupation, slto_kingdom_hero),
	      (troop_slot_eq, ":troop_no", slot_troop_is_prisoner, 0),
	      
	      #find current center
	      (party_get_attached_to, ":cur_center_no", ":party_no"),
	      (try_begin),
	        (lt, ":cur_center_no", 0),
	        (party_get_cur_town, ":cur_center_no", ":party_no"),
	      (try_end),
	      (try_begin),
	        (neg|is_between, ":cur_center_no", cities_begin, cities_end),
	        (assign, ":cur_center_no", -1),
	      (try_end),
	      
	      (store_troop_faction, ":faction_no", ":troop_no"),
	      
	      #        (party_get_slot, ":old_commander_party", ":party_no", slot_party_commander_party),
	      (party_get_slot, ":old_ai_state", ":party_no", slot_party_ai_state),
	      #        (party_get_slot, ":old_ai_object", ":party_no", slot_party_ai_object),
	      
	      (assign, ":cancel", 0),
	      (try_begin), #if we are retreating to a center keep retreating
	        (eq, ":old_ai_state", spai_retreating_to_center),
	        (neg|party_is_in_any_town, ":party_no"),
	        (assign, ":cancel", 1),
	      (try_end),
	      (eq, ":cancel", 0),
	      
	      (faction_get_slot, ":faction_ai_state",  ":faction_no", slot_faction_ai_state),
	      (faction_get_slot, ":faction_ai_object", ":faction_no", slot_faction_ai_object),
	      
	      
	      (assign, ":chance_move_to_home_center", 0),
	      (assign, ":target_move_to_home_center", -1),
	      (assign, ":chance_move_to_other_center", 0),
	      (assign, ":target_move_to_other_center", -1),
	      (assign, ":chance_besiege_enemy_center", 0),
	      (assign, ":target_besiege_enemy_center", -1),
	      (assign, ":chance_raid_around_center", 0),
	      (assign, ":target_raid_around_center", -1),
	      
	      (assign, ":chance_patrol_around_center", 0),
	      (assign, ":target_patrol_around_center", -1),
	      (assign, ":chance_raid_around_center", 0),
	      (assign, ":target_raid_around_center", -1),
	      (assign, ":chance_to_follow_other_party", 0),
	      (assign, ":target_to_follow_other_party", -1),
	      (assign, ":chance_stay", 0),
	      
	      #        (assign, ":is_besieging", 0),
	      #        (assign, ":under_siege", 0),
	      
	      (try_begin),
	        #          (is_between, ":cur_center_no", walled_cities_begin, walled_cities_end),
	        #          (party_slot_ge, ":cur_center_no", slot_town_is_besieged_by, 0),
	        #          (assign, ":under_siege", 1),
	      (try_end),
	      
	      
	      (try_begin),
	        (assign, ":target_move_to_home_center", -1), #Moving to home center
	        (try_begin),
	          (is_between, ":cur_center_no", cities_begin, cities_end), #already in our center
	          (party_slot_eq,  ":cur_center_no", slot_town_lord, ":troop_no"),
	          (assign, ":target_move_to_home_center", ":cur_center_no"),
	          (assign, ":chance_move_to_home_center", 100),
	        (try_end),
	        (try_begin),
	          (eq, ":target_move_to_home_center", -1),
	          (call_script, "script_cf_troop_get_random_leaded_center", ":troop_no"),#Can fail
	          (is_between, reg0, walled_cities_begin, walled_cities_end), # Do not move into villages
	          (assign, ":target_move_to_home_center", reg0),
	          (assign, ":chance_move_to_home_center", 50),
	        (try_end),
	      (try_end),
	      (try_begin),
	        (assign, ":target_move_to_other_center", -1),#Moving to other center
	        (try_begin),
	          (party_slot_eq, ":party_no", slot_party_ai_state, spai_holding_center),
	          (party_get_slot, ":target_move_to_other_center", ":party_no", slot_party_ai_object),
	          (assign, ":chance_move_to_other_center", 30),
	        (try_end),
	        (try_begin),
	          (eq, ":target_move_to_other_center", -1),
	          (call_script, "script_cf_select_random_center_with_faction", ":faction_no"),
	          (assign, ":target_move_to_other_center", reg0),
	          (assign, ":chance_move_to_other_center", 10),
	          (party_get_slot, ":lord_of_center", ":target_move_to_other_center", slot_town_lord),
	          (try_begin),
	            (call_script, "script_cf_troop_check_troop_is_enemy", ":troop_no", ":lord_of_center"),
	          (else_try),
	            (assign, ":chance_move_to_other_center", 0),
	          (try_end),
	        (try_end),
	      (try_end),
	      (try_begin),
	        (lt, "$party_relative_strength", 50),
	        (store_sub, ":factor", 100, "$party_relative_strength"),
	        (val_mul, ":chance_move_to_home_center", 200),
	        (val_div, ":chance_move_to_home_center", ":factor"),
	      (try_end),
	      (try_begin),
	        (gt,  "$ratio_of_prisoners", 50),
	        (val_mul, ":chance_move_to_home_center", 2),
	      (try_end),
	      (try_begin), #raid villages
	        (gt, "$party_relative_strength", 75),
	        (lt,  "$ratio_of_prisoners", 50),
	        (try_for_range, ":enemy_village_no", villages_begin, villages_end),
	          (store_faction_of_party, ":enemy_village_faction", ":enemy_village_no"),
	          (store_relation, ":reln", ":enemy_village_faction", ":faction_no"),
	          (lt, ":reln", 0),
	          (store_distance_to_party_from_party, ":dist", ":enemy_village_no", ":party_no"),
	          (lt, ":dist", 70),
	          (party_slot_eq, ":enemy_village_no", slot_town_state, 0), #village is not already raided
	          (store_random_in_range, ":rand", 0, 100),
	          (lt, ":rand", 5),
	          (assign, ":chance_raid_around_center", 20),
	          (assign, ":target_raid_around_center", ":enemy_village_no"),
	        (try_end),
	      (try_end),
	      (try_begin),
	        (gt, "$party_relative_strength", 65),
	        (lt,  "$ratio_of_prisoners", 50),
	        (eq, ":faction_ai_state", sfai_attacking_center),
	        (assign, ":target_besiege_enemy_center", ":faction_ai_object"),
	        (assign, ":chance_besiege_enemy_center", 30),
	      (try_end),
	      (try_begin), #patrol alarmed center.
	        (gt, "$party_relative_strength", 65),
	        (try_begin),
	          (party_slot_eq, ":party_no", slot_party_ai_state, spai_patrolling_around_center),
	          (party_get_slot, ":target_patrol_around_center", ":party_no", slot_party_ai_object),
	        (try_end),
	        (assign, ":best_patrol_score", 0),
	        (assign, ":best_patrol_target", -1),
	        (try_for_range, ":center_no", cities_begin, cities_end), #find closest center that has spotted enemies.
	          (store_distance_to_party_from_party, ":distance", ":party_no", ),
	          (lt, ":distance", 50),
	          (store_faction_of_party, ":center_faction", ":center_no"),
	          (eq, ":center_faction", ":faction_no"),
	          (party_slot_ge, ":center_no", slot_center_last_spotted_enemy, 0),
	          (store_sub, ":this_center_score", 100, ":distance"),
	          (try_begin),
	            (party_slot_eq, ":center_no", slot_town_lord, ":troop_no"),
	            (val_mul, ":this_center_score", 2),
	          (try_end),
	          (try_begin),
	            (gt, ":this_center_score", ":best_patrol_score"),
	            (assign, ":best_patrol_score", ":this_center_score"),
	            (assign, ":best_patrol_target", ":center_no"),
	          (try_end),
	        (try_end),
	        (try_begin),
	          (gt, ":best_patrol_score", 0),
	          (assign, ":target_patrol_around_center", ":best_patrol_target"),
	        (try_end),
	        (try_begin),
	          (is_between, ":target_patrol_around_center", cities_begin, cities_end),
	          (assign, ":chance_patrol_around_center", 100),
	        (try_end),
	      (try_end),
	      (try_begin), #follow other party
	        (gt, "$party_relative_strength", 75),
	        (neg|faction_slot_eq, ":faction_no", slot_faction_leader, ":troop_no"),
	        (assign, ":done", 0),
	        (try_for_range, ":other_hero", kingdom_heroes_begin, kingdom_heroes_end),
	          (eq, ":done", 0),
	          (neq, ":other_hero", ":troop_no"),
	          (store_troop_faction, ":troop_faction", ":other_hero"),
	          (eq, ":troop_faction", ":faction_no"),
	          (troop_get_slot, ":other_party", ":other_hero", slot_troop_leaded_party),
	          (ge, ":other_party", 0),
	          (neg|party_slot_ge, ":other_party", slot_party_commander_party, 0), #other party is not under command itself.
	          (store_distance_to_party_from_party, ":dist", ":other_party", ":party_no"),
	          (lt, ":dist", 25),
	          (party_get_slot, ":other_party_ai_state", ":other_party", slot_party_ai_state),
	          (this_or_next|eq, ":other_party_ai_state", spai_patrolling_around_center),
	          (this_or_next|eq, ":other_party_ai_state", spai_besieging_center),
	          (this_or_next|eq, ":other_party_ai_state", spai_raiding_around_center),
	          (eq, ":other_party_ai_state", spai_raiding_village),
	          (assign, ":chance_to_follow_other_party", 50),
	          (try_begin),
	            (faction_slot_eq, ":faction_no", slot_faction_leader, ":other_hero"),
	            (val_mul, ":chance_to_follow_other_party", 2),
	          (try_end),
	          (assign, ":target_to_follow_other_party", ":other_party"),
	        (try_end),
	      (try_end),
	      (try_begin),
	        (party_get_slot, ":ai_state", ":party_no", slot_party_ai_state),#Stay
	        (party_get_slot, ":ai_object", ":party_no", slot_party_ai_object),
	        (neq, ":ai_state", spai_undefined),
	        (assign, ":cancel_cur_action", 0),
	        (try_begin),
	          (eq, ":ai_state", spai_patrolling_around_center),
	          (neg|party_slot_ge, ":ai_object", slot_center_last_spotted_enemy, 0),
	          (store_random_in_range, ":rand", 0, 100),
	          (lt, ":rand", 25),
	          (assign, ":cancel_cur_action", 1),
	        (try_end),
	        #          (eq, ":is_besieging", 0),
	        (eq, ":cancel_cur_action", 0),
	        (assign, ":chance_stay", 100),
	      (try_end),
	      
	      ##        (try_begin),
	      ##          (eq, ":siege_going_badly", 1),
	      ##          (assign, ":chance_besiege_enemy_center", 0),
	      ##          (assign, ":chance_stay", 0),
	      ##        (try_end),
	      ##        (try_begin),
	      ##          (eq, ":siege_going_well", 1),
	      ##          (assign, ":chance_move_to_home_center", 0),
	      ##          (assign, ":chance_move_to_other_center", 0),
	      ##          (assign, ":chance_patrol_around_center", 0),
	      ##          (assign, ":chance_besiege_enemy_center", 0),
	      ##          (assign, ":chance_help_besieged_center", 0),
	      ##        (try_end),
	      
	      (assign, ":sum_chances", ":chance_move_to_home_center"),
	      (val_add, ":sum_chances", ":chance_move_to_other_center"),
	      (val_add, ":sum_chances", ":chance_raid_around_center"),
	      (val_add, ":sum_chances", ":chance_besiege_enemy_center"),
	      (val_add, ":sum_chances", ":chance_patrol_around_center"),
	      (val_add, ":sum_chances", ":chance_to_follow_other_party"),
	      (val_add, ":sum_chances", ":chance_stay"),
	      (store_random_in_range, ":random_no", 0, ":sum_chances"),
	      (val_sub, ":random_no", ":chance_move_to_home_center"),
	      (try_begin),
	        (lt, ":random_no", 0),
	        (party_set_ai_object, ":party_no", ":target_move_to_home_center"),
	        (party_set_ai_behavior, ":party_no", ai_bhvr_travel_to_party),
	        (party_set_slot, ":party_no", slot_party_ai_state, spai_holding_center),
	        (party_set_slot, ":party_no", slot_party_ai_object, ":target_move_to_home_center"),
	        (try_begin),
	          (is_between, ":cur_center_no", cities_begin, cities_end),
	          (party_detach, ":party_no"),
	        (try_end),
	        (party_set_flags, ":party_no", pf_default_behavior, 1),
	        (party_set_slot, ":party_no", slot_party_commander_party, -1),
	      (else_try),
	        (val_sub, ":random_no", ":chance_move_to_other_center"),
	        (lt, ":random_no", 0),
	        (party_set_ai_object, ":party_no", ":target_move_to_other_center"),
	        (party_set_ai_behavior, ":party_no", ai_bhvr_travel_to_party),
	        (party_set_flags, ":party_no", pf_default_behavior, 0),
	        (party_set_slot, ":party_no", slot_party_ai_state, spai_holding_center),
	        (party_set_slot, ":party_no", slot_party_ai_object, ":target_move_to_other_center"),
	        (try_begin),
	          (is_between, ":cur_center_no", cities_begin, cities_end),
	          (party_detach, ":party_no"),
	        (try_end),
	        (party_set_slot, ":party_no", slot_party_commander_party, -1),
	      (else_try),
	        (val_sub, ":random_no", ":chance_raid_around_center"),
	        (lt, ":random_no", 0),
	        (call_script, "script_party_set_ai_state", ":party_no", spai_raiding_around_center, ":target_raid_around_center"),
	        (party_set_slot, ":party_no", slot_party_commander_party, -1),
	      (else_try),
	        (val_sub, ":random_no", ":chance_besiege_enemy_center"),
	        (lt, ":random_no", 0),
	        (call_script, "script_party_set_ai_state", ":party_no", spai_besieging_center, ":target_besiege_enemy_center"),
	        (party_set_slot, ":party_no", slot_party_commander_party, -1),
	      (else_try),
	        (val_sub, ":random_no", ":chance_patrol_around_center"),
	        (lt, ":random_no", 0),
	        (party_set_ai_object, ":party_no", ":target_patrol_around_center"),
	        (party_set_ai_behavior, ":party_no", ai_bhvr_patrol_party),
	        (party_set_ai_patrol_radius, ":party_no", 5),
	        (party_set_flags, ":party_no", pf_default_behavior, 0),
	        (party_set_slot, ":party_no", slot_party_ai_state, spai_patrolling_around_center),
	        (party_set_slot, ":party_no", slot_party_ai_object, ":target_patrol_around_center"),
	        (try_begin),
	          (is_between, ":cur_center_no", cities_begin, cities_end),
	          (party_detach, ":party_no"),
	        (try_end),
	        (party_set_slot, ":party_no", slot_party_commander_party, -1),
	      (else_try),
	        (val_sub, ":random_no", ":chance_to_follow_other_party"),
	        (lt, ":random_no", 0),
	        (str_store_troop_name, s1, ":troop_no"),
	        (str_store_party_name, s2, ":target_to_follow_other_party"),
	        #          (display_message, "@{s1} started to follow {s2}"),
	        (party_set_slot, ":party_no", slot_party_commander_party, ":target_to_follow_other_party"),
	      (try_end),
	    (try_end),
	]),

	("cf_create_kingdom_party",
	  [
	    (store_script_param_1, ":faction_no"),
	    (store_script_param_2, ":party_type"),
	    
	    (str_store_faction_name, s7, ":faction_no"),
	    (assign, ":party_name_str", "str_no_string"),
	    
	    (faction_get_slot, ":reinforcements_a", ":faction_no", slot_faction_reinforcements_a),
	    (faction_get_slot, ":reinforcements_b", ":faction_no", slot_faction_reinforcements_b),
	    (faction_get_slot, ":reinforcements_c", ":faction_no", slot_faction_reinforcements_c),
	    
	    (try_begin),
	      (eq, ":party_type", spt_forager),
	      (assign, ":party_template", "pt_forager_party"),
	      #        (assign, ":party_name_str", "str_s7_foragers"),
	    (else_try),
	      (eq, ":party_type", spt_scout),
	      (assign, ":party_template", "pt_scout_party"),
	      #        (assign, ":party_name_str", "str_s7_scouts"),
	    (else_try),
	      (eq, ":party_type", spt_patrol),
	      (assign, ":party_template", "pt_patrol_party"),
	      #        (assign, ":party_name_str", "str_s7_patrol"),
	    (else_try),
	      (eq, ":party_type", spt_kingdom_caravan),
	      (assign, ":party_template", "pt_kingdom_caravan_party"),
	      #        (assign, ":party_name_str", "str_s7_caravan"),
	    (else_try),
	      (eq, ":party_type", spt_messenger),
	      (assign, ":party_template", "pt_messenger_party"),
	      #        (assign, ":party_name_str", "str_s7_messenger"),
	    (else_try),
	      (eq, ":party_type", spt_raider),
	      (assign, ":party_template", "pt_raider_party"),
	      (assign, ":party_name_str", "str_s7_raiders"),
	    (else_try),
	      (eq, ":party_type", spt_prisoner_train),
	      (assign, ":party_template", "pt_prisoner_train_party"),
	      #        (assign, ":party_name_str", "str_s7_prisoner_train"),
	    (else_try),
	      (eq, ":party_type", spt_deserter),
	      (assign, ":party_template", "pt_deserter_party"),
	    (try_end),
	    
	    (assign, ":result", -1),
	    (try_begin),
	      (call_script,"script_cf_select_random_center_with_faction", ":faction_no"),
	      (assign, ":spawn_center",reg0),
	      (set_spawn_radius, 1),
	      (spawn_around_party,":spawn_center",":party_template"),
	      (assign, ":result", reg0),
	      (party_set_faction, ":result", ":faction_no"),
	      (party_set_slot, ":result", slot_party_type, ":party_type"),
	      (party_set_slot, ":result", slot_party_ai_state, spai_undefined),
	      (try_begin),
	        (neq, ":party_name_str", "str_no_string"),
	        (party_set_name, ":result", ":party_name_str"),
	      (try_end),
	      
	      (try_begin),
	        (eq, ":party_type", spt_forager),
	        (party_add_template, ":result", ":reinforcements_a"),
	      (else_try),
	        (eq, ":party_type", spt_scout),
	        (party_add_template, ":result", ":reinforcements_c"),
	      (else_try),
	        (eq, ":party_type", spt_patrol),
	        (party_add_template, ":result", ":reinforcements_a"),
	        (party_add_template, ":result", ":reinforcements_b"),
	      (else_try),
	        (eq, ":party_type", spt_kingdom_caravan),
	        (party_add_template, ":result", ":reinforcements_b"),
	        (party_add_template, ":result", ":reinforcements_b"),
	        (party_set_ai_behavior,":result",ai_bhvr_travel_to_party),
	        (party_set_ai_object,":result",":spawn_center"),
	        (party_set_flags, ":result", pf_default_behavior, 1),
	        (store_sub, ":item_to_price_slot", slot_town_trade_good_prices_begin, trade_goods_begin),
	        (try_for_range, ":cur_goods", trade_goods_begin, trade_goods_end),
	          (store_add, ":cur_goods_price_slot", ":cur_goods", ":item_to_price_slot"),
	          (party_set_slot, ":result", ":cur_goods_price_slot", average_price_factor),
	        (try_end),
	      (else_try),
	        (eq, ":party_type", spt_messenger),
	        (faction_get_slot, ":messenger_troop", ":faction_no", slot_faction_messenger_troop),
	        (party_add_leader, ":result", ":messenger_troop"),
	        (party_set_ai_behavior,":result",ai_bhvr_travel_to_party),
	        (party_set_ai_object,":result",":spawn_center"),
	        (party_set_flags, ":result", pf_default_behavior, 0),
	      (else_try),
	        (eq, ":party_type", spt_raider),
	        (party_add_template, ":result", ":reinforcements_c"),
	        (party_add_template, ":result", ":reinforcements_b"),
	        (party_add_template, ":result", "pt_raider_captives"),
	      (else_try),
	        (eq, ":party_type", spt_prisoner_train),
	        (party_add_template, ":result", ":reinforcements_b"),
	        (party_add_template, ":result", ":reinforcements_a"),
	        (try_begin),
	          (call_script,"script_cf_faction_get_random_enemy_faction",":faction_no"),
	          (store_random_in_range,":r",0,2),
	          (try_begin),
	            (lt, ":r", 1),
	            (faction_get_slot, ":captive_reinforcements", reg0, slot_faction_reinforcements_b),
	          (else_try),
	            (faction_get_slot, ":captive_reinforcements", reg0, slot_faction_reinforcements_a),
	          (try_end),
	          (party_add_template, ":result", ":captive_reinforcements",1),
	        (else_try),
	          (party_add_template, ":result", "pt_default_prisoners"),
	        (try_end),
	      (else_try),
	        (eq, ":party_type", spt_deserter),
	        (party_set_faction, ":result", "fac_deserters"),
	        (faction_get_slot, ":deserter_troop", ":faction_no", slot_faction_deserter_troop),
	        (str_store_troop_name_plural, s0, ":deserter_troop"),
	        (party_set_name, ":result", "str_s0"),
	        (party_get_num_companions, ":num_deserters_in_party", ":result"),
	        (party_clear, ":result"),
	        (party_add_members, ":result", ":deserter_troop", ":num_deserters_in_party"),
	      (try_end),
	    (try_end),
	    (ge, ":result", 0),
	    (assign, reg0, ":result"),
	]),


	(store_script_param_1, ":troop_no"),
	(troop_get_slot, ":party_no", ":troop_no", slot_troop_leaded_party),
	(store_faction_of_party, ":faction_no", ":party_no"),
	(party_get_slot, ":ai_state", ":party_no", slot_party_ai_state),
	(party_get_slot, ":ai_object", ":party_no", slot_party_ai_object),
	(try_begin),
	  (eq, ":ai_state", spai_besieging_center),
	  (try_begin),
	    (store_distance_to_party_from_party, ":distance", ":party_no", ":ai_object"),
	    (lt, ":distance", 2),
	    (try_begin),
	      (party_slot_eq, ":ai_object", slot_town_is_besieged_by, -1),
	      (party_set_slot, ":ai_object", slot_town_is_besieged_by, ":party_no"),
	      (str_store_party_name, s1, ":ai_object"),
	      (str_store_troop_name, s2, ":troop_no"),
	      (str_store_faction_name, s3, ":faction_no"),
	      (display_message, "@{s1} has been besieged by {s2} of {s3}."),
	      (call_script, "script_village_set_state", ":ai_object", sts_under_siege),
	      #give siege locations to followers...
	    (try_end),
	    (party_get_battle_opponent, ":opponent", ":party_no"),
	    (lt, ":opponent", 0),
	    (call_script, "script_party_calculate_regular_strength", ":party_no"),
	    (assign, ":our_strength", reg0),
	    (party_collect_attachments_to_party, ":ai_object", "p_collective_enemy"),
	    (call_script, "script_party_calculate_regular_strength", "p_collective_enemy"),
	    (assign, ":castle_strength", reg0),
	    #            (assign, ":start_attack", 0),
	    (store_mul, ":three_times_castle_strength", ":castle_strength", 3),
	    (store_mul, ":ten_times_castle_strength", ":castle_strength", 10),
	    (assign, ":do_attack", 0),
	    (try_begin),
	      (gt, ":our_strength", ":three_times_castle_strength"),
	      (store_random_in_range, ":rand", 0, 100),
	      (this_or_next|lt, ":rand", 10),
	      (gt, ":our_strength", ":ten_times_castle_strength"), #we have enough strength for an attack
	      (assign, ":do_attack", 1),
	    (try_end),
	    
	    (try_begin),
	      (eq, ":do_attack", 1),
	      (party_set_ai_behavior, ":party_no", ai_bhvr_attack_party),
	      (party_set_ai_object, ":party_no", ":ai_object"),
	      (party_set_flags, ":party_no", pf_default_behavior, 0),
	    (else_try),
	      (party_set_ai_behavior, ":party_no", ai_bhvr_hold),
	      (party_set_flags, ":party_no", pf_default_behavior, 0),
	    (try_end),
	  (try_end),
	(else_try),
	  (eq, ":ai_state", spai_raiding_around_center),
	  (assign, ":done", 0),
	  (try_for_range, ":enemy_village_no", villages_begin, villages_end),
	    (eq, ":done", 0),
	    (store_faction_of_party, ":enemy_village_faction", ":enemy_village_no"),
	    (store_relation, ":reln", ":enemy_village_faction", ":faction_no"),
	    (lt, ":reln", 0),
	    (store_distance_to_party_from_party, ":dist", ":enemy_village_no", ":party_no"),
	    (lt, ":dist", 15),
	    (party_slot_eq, ":enemy_village_no", slot_town_state, 0), #village is not already raided
	    #CHANGE STATE TO RAID THIS VILLAGE
	    (call_script, "script_party_set_ai_state", ":party_no", spai_raiding_village, ":enemy_village_no"),
	    (assign, ":done", 1),
	    #            (assign, ":ai_state", spai_raiding_village),
	    #            (assign, ":ai_object", ":enemy_village_no"),
	    #            (assign, ":last", -1),
	  (try_end),
	  #          (ge, ":last", 0), #HACK: We make the script continue from the next block.
	(else_try),
	  (eq, ":ai_state", spai_raiding_village),
	  (try_begin),
	    (store_distance_to_party_from_party, ":distance", ":party_no", ":ai_object"),
	    (lt, ":distance", 2),
	    (try_begin),
	      (party_slot_eq, ":ai_object", slot_town_state, 0),
	      (call_script, "script_village_set_state", ":ai_object", sts_being_raided),
	      (party_set_slot, ":ai_object", slot_town_raided_by, ":party_no"),
	    (else_try),
	      (party_slot_eq, ":ai_object", slot_town_state, sts_being_raided),
	    (else_try),
	      #if anything other than being_raided leave
	      (call_script, "script_party_set_ai_state", ":party_no", spai_raiding_around_center, ":ai_object"),
	    (try_end),
	  (try_end),
	(else_try),
	  (eq, ":ai_state", spai_retreating_to_center),
	  (try_begin),
	    (party_get_battle_opponent, ":enemy_party", ":party_no"),
	    (ge, ":enemy_party", 0), #we are in a battle! we may be caught in a loop!
	    (call_script, "script_party_set_ai_state", ":party_no", spai_undefined, -1),
	    (party_set_flags, ":party_no", pf_default_behavior, 0),
	    (party_set_slot, ":party_no", slot_party_commander_party, -1),
	  (try_end),
	(else_try),
	  (eq, ":ai_state", spai_holding_center),
	  (party_get_attached_to, ":cur_town", ":party_no"),
	  # Make the party sortie outside, so that it will drive away any enemies??
	  (try_begin),
	    (is_between, ":cur_town", walled_cities_begin, walled_cities_end),
	    (assign, ":sortie_chance", 50),
	    (try_begin),
	      (party_get_attached_to, ":cur_town", ":party_no"),
	      (party_slot_ge, ":party_no", slot_town_is_besieged_by, 0), #town is under siege
	      (assign, ":sortie_chance", 5),
	    (try_end),
	    (store_random_in_range, ":rand", 0, 100),
	    (lt, ":rand", ":sortie_chance"),
	    (assign, ":enemies_nearby", 0),
	    (call_script, "script_party_calculate_regular_strength", ":party_no"),
	    (assign, ":our_strength", reg0),
	    (try_for_range, ":enemy_hero", kingdom_heroes_begin, kingdom_heroes_end),
	      (store_troop_faction, ":enemy_hero_faction", ":enemy_hero"),
	      (store_relation, ":reln", ":enemy_hero_faction", ":faction_no"),
	      (lt, ":reln", -1),
	      (troop_get_slot, ":enemy_party", ":enemy_hero", slot_troop_leaded_party),
	      (gt, ":enemy_party", 0),
	      (party_is_active, ":enemy_party"),
	      (store_distance_to_party_from_party, ":dist", ":enemy_party", ":party_no"),
	      (lt, ":dist", 7),
	      (call_script, "script_party_calculate_regular_strength", "p_collective_enemy"),
	      (gt, reg0, ":our_strength"),
	      (assign, ":enemies_nearby", 1),
	    (try_end),
	    (eq, ":enemies_nearby", 0),
	    (party_set_ai_behavior, ":party_no", ai_bhvr_travel_to_party),
	    (party_set_ai_object, ":party_no", ":ai_object"),
	    (party_set_flags, ":party_no", pf_default_behavior, 0),
	    (party_detach, ":party_no"),
	  (try_end),
	(try_end),

	("create_kingdom_party_if_below_limit",
	    [
	      (store_script_param_1, ":faction_no"),
	      (store_script_param_2, ":party_type"),
	      
	      (try_begin),
	        (eq, ":party_type", spt_deserter),
	        (assign, ":faction_no", "fac_deserters"),
	      (try_end),
	      
	      (call_script, "script_count_parties_of_faction_and_party_type", ":faction_no", ":party_type"),
	      (assign, ":party_count", reg0),
	      
	      (assign, ":party_count_limit", 0),
	      (try_begin),
	        (eq, ":party_type", spt_forager),
	        (assign, ":party_count_limit", 1),
	      (else_try),
	        (eq, ":party_type", spt_scout),
	        (assign, ":party_count_limit", 1),
	      (else_try),
	        (eq, ":party_type", spt_patrol),
	        (assign, ":party_count_limit", 1),
	      (else_try),
	        (eq, ":party_type", spt_messenger),
	        (assign, ":party_count_limit", 1),
	      (else_try),
	        (eq, ":party_type", spt_kingdom_caravan),
	        (assign, ":party_count_limit", 4),
	      (else_try),
	        (eq, ":party_type", spt_prisoner_train),
	        (assign, ":party_count_limit", 1),
	      (else_try),
	        (eq, ":party_type", spt_deserter),
	        (assign, ":party_count_limit", 1),
	      (try_end),
	      
	      (assign, reg0, -1),
	      (try_begin),
	        (lt, ":party_count", ":party_count_limit"),
	        (call_script,"script_cf_create_kingdom_party", ":faction_no", ":party_type"),
	      (try_end),
	  ]),

	  # script_troop_write_family_relations_to_s1
	      # Input: arg1 = troop_no
	      # Output: none
	      ("troop_write_family_relations_to_s1",
	        [
	          (store_script_param_1, ":troop_no"),
	          (assign, ":num_family", 0),
	          (try_for_range, ":slot_no", slot_troop_family_begin, slot_troop_family_end),
	            (troop_slot_ge, ":troop_no", ":slot_no", 1),
	            (val_add, ":num_family", 1),
	          (try_end),
	          
	          (troop_get_type, ":gender", ":troop_no"),
	          (try_begin),
	            (eq, ":gender", 0),
	            (str_store_string, s5, "str_he"),
	          (else_try),
	            (str_store_string, s5, "str_she"),
	          (try_end),
	          
	          (try_begin),
	            (gt, ":num_family", 1),
	            (try_for_range, ":i_family", 1, ":num_family"),
	              (call_script, "script_write_family_relation_as_s3s_s2_to_s4", ":troop_no", ":i_family"),
	              (str_store_string_reg, s50, s4),
	              (try_begin),
	                (eq, ":i_family", 1),
	                (call_script, "script_write_family_relation_as_s3s_s2_to_s4", ":troop_no", 0),
	                (str_store_string_reg, s51, s4),
	                (str_store_string, s51, "str_s50_and_s51"),
	              (else_try),
	                (str_store_string, s51, "str_s50_comma_s51"),
	              (try_end),
	            (try_end),
	            (str_store_string, s1, "str_s5_is_s51"),
	          (else_try),
	            (eq, ":num_family", 1),
	            (call_script, "script_write_family_relation_as_s3s_s2_to_s4", ":troop_no", 0),
	            (str_store_string_reg, s51, s4),
	            (str_store_string, s1, "str_s5_is_s51"),
	          (else_try),
	            (str_store_string, s1, "str_blank_string"),
	          (try_end),
	      ]),
	# script_decide_kingdom_party_ai
	  # Input: none
	  # Output: none
	  #called from triggers
	  ("decide_kingdom_party_ai",
	    [
	      (store_script_param_1, ":troop_no"),
	      (try_begin),
	        (troop_slot_eq, ":troop_no", slot_troop_occupation, slto_kingdom_hero),
	        (troop_slot_eq, ":troop_no", slot_troop_is_prisoner, 0),
	        (troop_get_slot, ":party_no", ":troop_no", slot_troop_leaded_party),
	        (gt, ":party_no", 0),
	        
	        (call_script, "script_party_count_fit_for_battle", ":party_no"),
	        (assign, ":party_fit_for_battle", reg0),
	        
	        (call_script, "script_party_get_ideal_size", ":party_no"),
	        (assign, ":ideal_size", reg0),
	        (store_mul, "$party_relative_strength", ":party_fit_for_battle", 100),
	        (val_div, "$party_relative_strength", ":ideal_size"),
	        
	        (call_script, "script_party_count_prisoners", ":party_no"),
	        (assign, ":num_prisoners", reg0),
	        (store_div, "$ratio_of_prisoners", ":num_prisoners", ":party_fit_for_battle"),
	        
	        (call_script, "script_kingdom_hero_decide_next_ai_state", ":troop_no"),
	        (try_begin),
	          (party_get_slot, ":commander_party", ":party_no", slot_party_commander_party),
	          (ge, ":commander_party", 0),
	          (try_begin),
	            (gt, "$party_relative_strength", 40),
	            (lt,  "$ratio_of_prisoners", 50),
	            (call_script, "script_party_decide_next_ai_state_under_command", ":party_no"),
	          (else_try),
	            (party_set_slot, ":party_no", slot_party_commander_party, -1), #cancel escorting.
	          (try_end),
	        (try_end),
	      (try_end),
	  ]),
	  
	  # script_party_decide_next_ai_state_under_command
	  # Input: arg1 = party_no
	  # Output: none
	  #called from triggers
	  ("party_decide_next_ai_state_under_command",
	    [
	      (store_script_param_1, ":party_no"),
	      (party_get_slot, ":commander_party", ":party_no", slot_party_commander_party),
	      #      (party_get_slot, ":ai_state", ":party_no", slot_party_ai_state),
	      #      (party_get_slot, ":ai_object", ":party_no", slot_party_ai_object),
	      (party_get_slot, ":commander_ai_state", ":commander_party", slot_party_ai_state),
	      (party_get_slot, ":commander_ai_object", ":commander_party", slot_party_ai_object),
	      
	      (store_distance_to_party_from_party, ":distance_to_commander", ":party_no", ":commander_party"),
	      (try_begin),
	        (gt, ":distance_to_commander", 5),
	        (call_script, "script_party_set_ai_state", ":party_no", spai_accompanying_army, ":commander_party"),
	      (else_try),
	        (try_begin),
	          (eq, ":commander_party", "p_main_party"),
	          (call_script, "script_party_set_ai_state", ":party_no", spai_accompanying_army, "p_main_party"),
	        (else_try),
	          (eq, ":commander_ai_state", spai_besieging_center),
	          (call_script, "script_party_set_ai_state", ":party_no", spai_besieging_center, ":commander_ai_object"),
	        (try_end),
	      (try_end),
	  ]),

	# script_give_center_to_lord
	  # Input: arg1 = center_no, arg2 = lord_troop
	  ("give_center_to_lord",
	    [
	      (store_script_param_1, ":center_no"),
	      (store_script_param_2, ":lord_troop_id"),
	      
	      
	      (party_get_slot, ":old_lord_troop_id", ":center_no", slot_town_lord),
	      
	      (store_troop_faction, ":lord_troop_faction", ":lord_troop_id"),
	      (try_begin),
	        (eq, ":lord_troop_id", "trp_player"),
	        (gt, "$players_kingdom", 0),
	        (party_set_faction, ":center_no", "$players_kingdom"),
	      (else_try),
	        (party_set_faction, ":center_no", ":lord_troop_faction"),
	      (try_end),
	      (party_set_slot, ":center_no", slot_town_lord, ":lord_troop_id"),
	      
	      #      (str_store_party_name_link, s7, ":center_no"),
	      #      (str_store_troop_name_link, s8, ":lord_troop_id"),
	      #      (display_log_message, "@{s7} has been given to {s8}."),
	      
	      (try_begin),
	        (this_or_next|party_slot_eq, ":center_no", slot_party_type, spt_town),
	        (party_slot_eq, ":center_no", slot_party_type, spt_castle),
	        (troop_get_slot, ":cur_banner", ":lord_troop_id", slot_troop_banner_scene_prop),
	        (gt, ":cur_banner", 0),
	        (val_sub, ":cur_banner", "spr_banner_a"),
	        (val_add, ":cur_banner", "icon_banner_01"),
	        (party_set_banner_icon, ":center_no", ":cur_banner"),
	      (try_end),
	      
	      (try_begin),
	        (eq, ":lord_troop_id", "trp_player"),
	        (party_get_slot, ":center_relation", ":center_no", slot_center_player_relation),
	        (is_between, ":center_relation", -4, 5),
	        (call_script, "script_change_player_relation_with_center", ":center_no", 5),
	      (try_end),
	      
	      (call_script, "script_update_troop_notes", ":lord_troop_id"),
	      (call_script, "script_update_center_notes", ":center_no"),
	      (call_script, "script_update_faction_notes", ":lord_troop_faction"),
	      (try_begin),
	        (ge, ":old_lord_troop_id", 0),
	        (call_script, "script_update_troop_notes", ":old_lord_troop_id"),
	        (store_troop_faction, ":old_lord_troop_faction", ":old_lord_troop_id"),
	        (call_script, "script_update_faction_notes", ":old_lord_troop_faction"),
	      (try_end),
	  ]),
	# script_create_kingdom_hero_party
	  # Input: arg1 = troop_no, arg2 = center_no
	  # Output: $pout_party = party_no
	  ("create_kingdom_hero_party",
	    [
	      (store_script_param_1, ":troop_no"),
	      (store_script_param_2, ":center_no"),
	      
	      #      (store_faction_of_party, ":center_faction", ":center_no"),
	      (store_troop_faction, ":troop_faction_no", ":troop_no"),
	      
	      
	      #      (faction_get_slot, ":reinforcements_a", ":troop_faction_no", slot_faction_reinforcements_a),
	      #      (faction_get_slot, ":reinforcements_b", ":troop_faction_no", slot_faction_reinforcements_b),
	      #      (faction_get_slot, ":reinforcements_c", ":troop_faction_no", slot_faction_reinforcements_c),
	      
	      
	      (assign, "$pout_party", -1),
	      (set_spawn_radius,0),
	      (spawn_around_party,":center_no", "pt_kingdom_hero_party"),
	      (assign, "$pout_party", reg0),
	      
	      
	      (party_set_faction, "$pout_party", ":troop_faction_no"),
	      (party_set_slot, "$pout_party", slot_party_type, spt_kingdom_hero_party),
	      (party_set_slot, "$pout_party", slot_party_ai_state, spai_undefined),
	      (troop_set_slot, ":troop_no", slot_troop_leaded_party, "$pout_party"),
	      (party_add_leader, "$pout_party", ":troop_no"),
	      (str_store_troop_name, s5, ":troop_no"),
	      (party_set_name, "$pout_party", "str_s5_s_party"),
	      
	      (party_set_slot, "$pout_party", slot_party_commander_party, -1), #we need this because 0 is player's party!
	      
	      (assign, ":num_tries", 20),
	      (try_begin),
	        (store_troop_faction, ":troop_kingdom", ":troop_no"),
	        (faction_slot_eq, ":troop_kingdom", slot_faction_leader, ":troop_no"),
	        (assign, ":num_tries", 50),
	      (try_end),
	      
	      (try_for_range, ":unused", 0, ":num_tries"),
	        (call_script, "script_hire_men_to_kingdom_hero_party", ":troop_no" ),
	      (else_try),
	        (assign, ":num_tries", 0),
	      (try_end),
	      
	      #Setting the flag icon
	      (troop_get_slot, ":cur_banner", ":troop_no", slot_troop_banner_scene_prop),
	      (try_begin),
	        (gt, ":cur_banner", 0),
	        (val_sub, ":cur_banner", "spr_banner_a"),
	        (val_add, ":cur_banner", "icon_banner_01"),
	        (party_set_banner_icon, "$pout_party", ":cur_banner"),
	      (try_end),
	  ]), 

	  
	  
	  # script_process_sieges - needs modification
	  # Input: none
	  # Output: none
	  #called from triggers
	  
	  
	"""
